export const allowedStatuses = [
    "active",
    "expired",
    "pending",
    "inactive",
    "renewed"
];

export const parseBoolean = (value) => {
    return value === "true" || value === true;
};

export const formatDomain = (domain) => {
    return {
        id: domain.id,
        domain_name: domain.domain_name,
        client_name: domain.client_name,
        client_email: domain.client_email,
        registrar: domain.registrar,
        expiry_date: domain.expiry_date,
        status: domain.status,
        auto_renew: domain.auto_renew,
        cost: domain.cost,
        ssl_enabled: domain.ssl_enabled,
        ssl_expiry_date: domain.ssl_expiry_date,
        last_renewed_at: domain.last_renewed_at
    };
};

export const handleDomainError = (res, error) => {
    console.log("Domain Error:", error);

    if (error.name === "SequelizeUniqueConstraintError") {
        return res.status(409).json({
            success: false,
            message: "Domain name already exists"
        });
    }

    if (error.name === "SequelizeValidationError") {
        return res.status(400).json({
            success: false,
            message: error.errors?.[0]?.message || "Invalid domain data"
        });
    }

    return res.status(500).json({
        success: false,
        message: "Internal Server Error"
    });
};
