import { z } from 'zod'

export const agentAppStatusSchema = z.enum(['active', 'inactive', 'pending', 'approved', 'rejected'])

export const agentAppSchema = z.object({
  id: z.number(),
  agent_id: z.number(),
  agent_name: z.string(),
  application_id: z.number(),
  app_name: z.string(),
  status: agentAppStatusSchema,
  discount: z.number(),
  balance: z.number(),
  card_types: z.array(z.object({
    card_type_id: z.number(),
    can_generate: z.boolean(),
  })).optional(),
  created_at: z.string(),
  updated_at: z.string().optional(),
  is_received: z.boolean().optional(),
})

export const agentRequestSchema = z.object({
  id: z.number(),
  admin_id: z.number(),
  admin_name: z.string(),
  agent_id: z.number(),
  agent_name: z.string(),
  application_id: z.number(),
  app_name: z.string(),
  status: z.enum(['pending', 'approved', 'rejected']),
  message: z.string().optional(),
  created_at: z.string(),
})

export type AgentApp = z.infer<typeof agentAppSchema>
export type AgentRequest = z.infer<typeof agentRequestSchema>

export interface CombinedItem {
  id: number
  agent_id: number
  agent_name: string
  application_id: number
  app_name: string
  status: string
  discount: number
  balance: number
  card_types?: Array<{ card_type_id: number, can_generate: boolean }>
  created_at: string
  itemType: 'authorization' | 'request' | 'my_request'
  hasAuthorization: boolean
  authorizationId: number | null
  is_received?: boolean
}
