import { HttpStep } from '../../HttpStep.js';
export const SetCookieStepKind = 'HttpAction#SetCookie';
export class SetCookieStep extends HttpStep {
    kind = SetCookieStepKind;
    /**
     * The name of the cookie
     */
    name = '';
    /**
     * The URL associated with the cookie.
     * When not set it uses the request URL or the request URL of the last redirect.
     */
    url;
    /**
     * The cookie expiration time. It can be a valid cookie date or a string representing a relative time to "now"
     * like `4d`, `600s`, etc.
     */
    expires;
    /**
     * Whether the cookie is host only
     */
    hostOnly;
    /**
     * Whether the cookie is HTTP only
     */
    httpOnly;
    /**
     * Whether the cookie is HTTPS only
     */
    secure;
    /**
     * Whether the cookie is a session cookie
     */
    session;
    /**
     * The SameSite parameter of the cookie.
     * https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies#creating_cookies
     */
    sameSite;
    constructor(nameOrInit, url) {
        super();
        if (!nameOrInit) {
            return;
        }
        if (typeof nameOrInit === 'object') {
            const typed = nameOrInit;
            this.new({ ...typed, kind: SetCookieStepKind });
        }
        else if (typeof nameOrInit === 'string') {
            this.new({
                kind: SetCookieStepKind,
                name: nameOrInit,
                enabled: true,
                url,
            });
        }
    }
    new(init) {
        super.new(init);
        this.kind = SetCookieStepKind;
        this.name = init.name;
        if (init.url) {
            this.url = init.url;
        }
        else {
            this.url = undefined;
        }
        if (init.expires) {
            this.expires = init.expires;
        }
        else {
            this.expires = undefined;
        }
        if (typeof init.hostOnly === 'boolean') {
            this.hostOnly = init.hostOnly;
        }
        else {
            this.hostOnly = undefined;
        }
        if (typeof init.httpOnly === 'boolean') {
            this.httpOnly = init.httpOnly;
        }
        else {
            this.httpOnly = undefined;
        }
        if (typeof init.secure === 'boolean') {
            this.secure = init.secure;
        }
        else {
            this.secure = undefined;
        }
        if (typeof init.session === 'boolean') {
            this.session = init.session;
        }
        else {
            this.session = undefined;
        }
        if (typeof init.sameSite === 'boolean') {
            this.sameSite = init.sameSite;
        }
        else {
            this.sameSite = undefined;
        }
    }
    checkValidity() {
        const { name } = this;
        return !!name;
    }
    toJSON() {
        const result = {
            ...super.toJSON(),
            kind: SetCookieStepKind,
            name: this.name,
        };
        if (this.url) {
            result.url = this.url;
        }
        if (this.expires) {
            result.expires = this.expires;
        }
        if (typeof this.hostOnly === 'boolean') {
            result.hostOnly = this.hostOnly;
        }
        if (typeof this.httpOnly === 'boolean') {
            result.httpOnly = this.httpOnly;
        }
        if (typeof this.secure === 'boolean') {
            result.secure = this.secure;
        }
        if (typeof this.session === 'boolean') {
            result.session = this.session;
        }
        if (typeof this.sameSite === 'boolean') {
            result.sameSite = this.sameSite;
        }
        return result;
    }
}
//# sourceMappingURL=SetCookieStep.js.map