import type { NextRequest } from "next/server";
import type { NextResponse } from "next/server";
import {CURRENT_CURRENCY,CURRENT_LOCAL,CURRENT_CHANNEL} from "@/utils/constants";
import {currencyCookieOptions} from "@/utils/constants/server";

export function handleCurrency(
    request: NextRequest,
    response: NextResponse
) {

    const currency = request.cookies.get(CURRENT_CURRENCY);
    const local = request.cookies.get(CURRENT_LOCAL);
    const channel = request.cookies.get(CURRENT_CHANNEL);
    const defaultCurrency = process.env.DEFAULT_CURRENCY;
    const defaultLocal = process.env.DEFAULT_LOCAL;
    const defaultChannel = process.env.DEFAULT_CHANNEL;

    if (!currency && defaultCurrency) {
        
        response.cookies.set(CURRENT_CURRENCY,defaultCurrency,currencyCookieOptions);
    }
    if (!local && defaultLocal) {
        
        response.cookies.set(CURRENT_LOCAL,defaultLocal,currencyCookieOptions);
    }
    if (!channel && defaultChannel) {
        
        response.cookies.set(CURRENT_CHANNEL,defaultChannel,currencyCookieOptions);
    }

    return response;

}