import routes from "@/routes"
import { AuthPayload } from "../types"
import { getAuthHeaders } from "../utils"
import { Currency } from "@/components/PaymentTable"

export type Payload = AuthPayload

type SubscriptionType = "DAY" | "WEEK" | "MONTH" | "YEAR"
type SubscriptionStatus = "ACTIVE" | "CANCELLED"
type Date = string | null

export interface UserSubscription {
  id: string,
  subscriptionType: SubscriptionType,
  subscriptionStatus: SubscriptionStatus,
  billingPeriod: SubscriptionType,
  lastPaymentOn: Date,
  renewalDate: Date,
  renewalAmount: number,
  currency: keyof typeof Currency,
  cancellationDate: Date
}

export interface ResponseGet {
  status: "success" | string;
  data: UserSubscription[];
}

export const createRequestGet = ({ token }: Payload): Request => {
  const url = new URL(routes.server.userSubscriptions())
  return new Request(url, { method: 'GET', headers: getAuthHeaders(token) })
}

export type UserSubscriptionAction = "cancel" | "discount_50" | "pause_30" | "pause_60" | "free_chat_30"

export interface PayloadAction extends AuthPayload {
  subscriptionId: string;
  action: UserSubscriptionAction;
}

export interface ResponseAction {
  status: "success" | string;
  data: PayloadAction;
}

export const createRequestAction = ({ token, subscriptionId, action }: PayloadAction): Request => {
  const url = new URL(routes.server.userSubscriptionAction(subscriptionId, action))
  return new Request(url, { method: 'POST', headers: getAuthHeaders(token) })
}
