"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.AuthStatusResponseDto = exports.OAuthBackchannelLogoutDto = exports.OAuthAuthorizeResponseDto = exports.OAuthConfigDto = exports.OAuthCallbackDto = exports.ValidateAccessTokenResponseDto = exports.PinCodeChangeDto = exports.SessionUnlockDto = exports.PinCodeResetDto = exports.PinCodeSetupDto = exports.ChangePasswordDto = exports.SignUpDto = exports.LogoutResponseDto = exports.LoginResponseDto = exports.LoginCredentialDto = exports.pinCodeRegex = void 0;
exports.mapLoginResponse = mapLoginResponse;
const openapi = require("@nestjs/swagger");
const nestjs_zod_1 = require("nestjs-zod");
const enum_1 = require("../enum");
const validation_1 = require("../validation");
const zod_1 = __importDefault(require("zod"));
exports.pinCodeRegex = /^\d{6}$/;
const LoginCredentialSchema = zod_1.default
    .object({
    email: validation_1.toEmail.describe('User email').meta({ example: 'testuser@email.com' }),
    password: zod_1.default.string().describe('User password').meta({ example: 'password' }),
})
    .meta({ id: 'LoginCredentialDto' });
const LoginResponseSchema = zod_1.default
    .object({
    accessToken: zod_1.default.string().describe('Access token'),
    userId: zod_1.default.uuidv4().describe('User ID'),
    userEmail: validation_1.toEmail.describe('User email'),
    name: zod_1.default.string().describe('User name'),
    profileImagePath: zod_1.default.string().describe('Profile image path'),
    isAdmin: zod_1.default.boolean().describe('Is admin user'),
    shouldChangePassword: zod_1.default.boolean().describe('Should change password'),
    isOnboarded: zod_1.default.boolean().describe('Is onboarded'),
})
    .meta({ id: 'LoginResponseDto' });
function mapLoginResponse(entity, accessToken) {
    const onboardingMetadata = entity.metadata.find((item) => item.key === enum_1.UserMetadataKey.Onboarding)?.value;
    return {
        accessToken,
        userId: entity.id,
        userEmail: entity.email,
        name: entity.name,
        isAdmin: entity.isAdmin,
        profileImagePath: entity.profileImagePath,
        shouldChangePassword: entity.shouldChangePassword,
        isOnboarded: onboardingMetadata?.isOnboarded ?? false,
    };
}
const LogoutResponseSchema = zod_1.default
    .object({
    successful: zod_1.default.boolean().describe('Logout successful'),
    redirectUri: zod_1.default.string().describe('Redirect URI'),
})
    .meta({ id: 'LogoutResponseDto' });
const SignUpSchema = LoginCredentialSchema.extend({
    name: zod_1.default.string().describe('User name').meta({ example: 'Admin' }),
}).meta({ id: 'SignUpDto' });
const ChangePasswordSchema = zod_1.default
    .object({
    password: zod_1.default.string().describe('Current password').meta({ example: 'password' }),
    newPassword: zod_1.default.string().min(8).describe('New password (min 8 characters)').meta({ example: 'password' }),
    invalidateSessions: zod_1.default.boolean().default(false).optional().describe('Invalidate all other sessions'),
})
    .meta({ id: 'ChangePasswordDto' });
const PinCodeSetupSchema = zod_1.default
    .object({
    pinCode: zod_1.default.string().regex(exports.pinCodeRegex).describe('PIN code (4-6 digits)').meta({ example: '123456' }),
})
    .meta({ id: 'PinCodeSetupDto' });
const PinCodeResetSchema = zod_1.default.object({
    pinCode: zod_1.default.string().regex(exports.pinCodeRegex).optional().describe('New PIN code (4-6 digits)').meta({ example: '123456' }),
    password: zod_1.default
        .string()
        .optional()
        .describe('User password (required if PIN code is not provided)')
        .meta({ example: 'password' }),
});
const SessionUnlockSchema = PinCodeResetSchema.meta({ id: 'SessionUnlockDto' });
const PinCodeChangeSchema = PinCodeResetSchema.extend({
    newPinCode: zod_1.default.string().regex(exports.pinCodeRegex).describe('New PIN code (4-6 digits)'),
}).meta({ id: 'PinCodeChangeDto' });
const ValidateAccessTokenResponseSchema = zod_1.default
    .object({
    authStatus: zod_1.default.boolean().describe('Authentication status'),
})
    .meta({ id: 'ValidateAccessTokenResponseDto' });
const OAuthCallbackSchema = zod_1.default
    .object({
    url: zod_1.default.string().min(1).describe('OAuth callback URL'),
    state: zod_1.default.string().optional().describe('OAuth state parameter'),
    codeVerifier: zod_1.default.string().optional().describe('OAuth code verifier (PKCE)'),
})
    .meta({ id: 'OAuthCallbackDto' });
const OAuthConfigSchema = zod_1.default
    .object({
    redirectUri: zod_1.default.string().describe('OAuth redirect URI'),
    state: zod_1.default.string().optional().describe('OAuth state parameter'),
    codeChallenge: zod_1.default.string().optional().describe('OAuth code challenge (PKCE)'),
})
    .meta({ id: 'OAuthConfigDto' });
const OAuthAuthorizeResponseSchema = zod_1.default
    .object({
    url: zod_1.default.string().describe('OAuth authorization URL'),
})
    .meta({ id: 'OAuthAuthorizeResponseDto' });
const OAuthBackchannelLogoutSchema = zod_1.default
    .object({ logout_token: zod_1.default.string().describe('OAuth logout token') })
    .meta({ id: 'OAuthBackchannelLogoutDto' });
const AuthStatusResponseSchema = zod_1.default
    .object({
    pinCode: zod_1.default.boolean().describe('Has PIN code set'),
    password: zod_1.default.boolean().describe('Has password set'),
    isElevated: zod_1.default.boolean().describe('Is elevated session'),
    expiresAt: zod_1.default.string().optional().describe('Session expiration date'),
    pinExpiresAt: zod_1.default.string().optional().describe('PIN expiration date'),
})
    .meta({ id: 'AuthStatusResponseDto' });
class LoginCredentialDto extends (0, nestjs_zod_1.createZodDto)(LoginCredentialSchema) {
    static _OPENAPI_METADATA_FACTORY() {
        return {};
    }
}
exports.LoginCredentialDto = LoginCredentialDto;
class LoginResponseDto extends (0, nestjs_zod_1.createZodDto)(LoginResponseSchema) {
    static _OPENAPI_METADATA_FACTORY() {
        return {};
    }
}
exports.LoginResponseDto = LoginResponseDto;
class LogoutResponseDto extends (0, nestjs_zod_1.createZodDto)(LogoutResponseSchema) {
    static _OPENAPI_METADATA_FACTORY() {
        return {};
    }
}
exports.LogoutResponseDto = LogoutResponseDto;
class SignUpDto extends (0, nestjs_zod_1.createZodDto)(SignUpSchema) {
    static _OPENAPI_METADATA_FACTORY() {
        return {};
    }
}
exports.SignUpDto = SignUpDto;
class ChangePasswordDto extends (0, nestjs_zod_1.createZodDto)(ChangePasswordSchema) {
    static _OPENAPI_METADATA_FACTORY() {
        return {};
    }
}
exports.ChangePasswordDto = ChangePasswordDto;
class PinCodeSetupDto extends (0, nestjs_zod_1.createZodDto)(PinCodeSetupSchema) {
    static _OPENAPI_METADATA_FACTORY() {
        return {};
    }
}
exports.PinCodeSetupDto = PinCodeSetupDto;
class PinCodeResetDto extends (0, nestjs_zod_1.createZodDto)(PinCodeResetSchema) {
    static _OPENAPI_METADATA_FACTORY() {
        return {};
    }
}
exports.PinCodeResetDto = PinCodeResetDto;
class SessionUnlockDto extends (0, nestjs_zod_1.createZodDto)(SessionUnlockSchema) {
    static _OPENAPI_METADATA_FACTORY() {
        return {};
    }
}
exports.SessionUnlockDto = SessionUnlockDto;
class PinCodeChangeDto extends (0, nestjs_zod_1.createZodDto)(PinCodeChangeSchema) {
    static _OPENAPI_METADATA_FACTORY() {
        return {};
    }
}
exports.PinCodeChangeDto = PinCodeChangeDto;
class ValidateAccessTokenResponseDto extends (0, nestjs_zod_1.createZodDto)(ValidateAccessTokenResponseSchema) {
    static _OPENAPI_METADATA_FACTORY() {
        return {};
    }
}
exports.ValidateAccessTokenResponseDto = ValidateAccessTokenResponseDto;
class OAuthCallbackDto extends (0, nestjs_zod_1.createZodDto)(OAuthCallbackSchema) {
    static _OPENAPI_METADATA_FACTORY() {
        return {};
    }
}
exports.OAuthCallbackDto = OAuthCallbackDto;
class OAuthConfigDto extends (0, nestjs_zod_1.createZodDto)(OAuthConfigSchema) {
    static _OPENAPI_METADATA_FACTORY() {
        return {};
    }
}
exports.OAuthConfigDto = OAuthConfigDto;
class OAuthAuthorizeResponseDto extends (0, nestjs_zod_1.createZodDto)(OAuthAuthorizeResponseSchema) {
    static _OPENAPI_METADATA_FACTORY() {
        return {};
    }
}
exports.OAuthAuthorizeResponseDto = OAuthAuthorizeResponseDto;
class OAuthBackchannelLogoutDto extends (0, nestjs_zod_1.createZodDto)(OAuthBackchannelLogoutSchema) {
    static _OPENAPI_METADATA_FACTORY() {
        return {};
    }
}
exports.OAuthBackchannelLogoutDto = OAuthBackchannelLogoutDto;
class AuthStatusResponseDto extends (0, nestjs_zod_1.createZodDto)(AuthStatusResponseSchema) {
    static _OPENAPI_METADATA_FACTORY() {
        return {};
    }
}
exports.AuthStatusResponseDto = AuthStatusResponseDto;
//# sourceMappingURL=auth.dto.js.map