import type { AdminObservedProductItem } from '@/types/admin'

export type EditableBinding = {
  id: string
  provider: string
  platform: string
  shopId: string
  shopName: string
  skuCode: string
  skuName: string
  profileKey: string
  enabled: boolean
  priority: number
  externalSkuCode: string
  externalItemId: string
  externalSkuName: string
  resolvedSkuName: string
}

export type SaveBindingPayload = {
  provider: string
  platform: string
  shopId: string
  shopName: string
  skuCode: string
  skuName: string
  profileKey: string
  enabled: boolean
  priority: number
  match: {
    externalSkuCode: string
    externalItemId: string
    externalSkuName: string
    config: {
      resolvedSkuName: string
    }
  }
}

export type ValidationField = 'skuCode' | 'match' | 'profileKey' | 'shopId'

export type ValidationState = {
  bindingId: string
  field: ValidationField
  message: string
} | null

export type ImportableProductCandidate = Pick<
  AdminObservedProductItem,
  | 'provider'
  | 'platform'
  | 'shopId'
  | 'shopName'
  | 'externalSkuCode'
  | 'externalItemId'
  | 'externalSkuName'
> & {}

export const PROFILE_OPTIONS = [
  { label: '腾讯领取兑换', value: 'tencent_claim_redeem' },
  { label: '腾讯领取兑换（半自动+人工）', value: 'tencent_claim_assisted' },
  { label: '快手 Cloud 履约', value: 'kuaishou_ct_assisted' },
  { label: '人工发货', value: 'manual_review' },
]

export const VALID_PROFILE_KEYS = new Set(PROFILE_OPTIONS.map((item) => item.value))
