import type { BusinessPrimaryColorId } from '../utils/businessPrimaryColors'
import type { DashboardLocale } from '../services/businessSettingsService'

export interface BusinessOwnerInfo {
  name: string | null
  cellNumber: string | null
}

export interface BusinessDomainInfo {
  host: string | null
  sslEnabled: boolean | null
}

export interface BusinessListItem {
  id: string
  name: string
  createdAt: string
  domainId: number | null
  domain: string | null
  sslEnabled: boolean | null
  ownerName: string | null
  ownerNameEn: string | null
  ownerCellNumber: string | null
  isActive: boolean
  primaryColor: BusinessPrimaryColorId
  defaultLocale: DashboardLocale
  oldBusinessId: string | null
}

export type MigrateFromOldEntity =
  | 'product_categories'
  | 'product'
  | 'customer_categories'
  | 'customer'
  | 'blog_categories'
  | 'blog'
  | 'portfolio_categories'
  | 'portfolio'

export type PurgeBusinessDataEntity = MigrateFromOldEntity

export type MigrateEntityResult =
  | {
      created: number
      skipped: number
      total: number
      imagesCopied?: number
      imagesResized?: number
      imagesFailed?: number
      titlesUpdated?: number
      skippedInvalidCell?: number
      skippedAlreadyLinked?: number
      skippedCreateFailed?: number
    }
  | { status: 'not_implemented' }

export type PurgeEntityResult =
  | {
      deleted: number
      imagesDeleted?: number
    }
  | { status: 'not_implemented' }

export interface MigrateFromOldPayload {
  oldBusinessId: number
  entities: MigrateFromOldEntity[]
}

export interface MigrateFromOldResponse {
  businessId: string
  oldBusinessId: string
  entities: MigrateFromOldEntity[]
  status: 'ok' | 'partial' | 'linked'
  message: string
  results?: Partial<Record<MigrateFromOldEntity, MigrateEntityResult>>
}

export interface PurgeBusinessDataPayload {
  entities: PurgeBusinessDataEntity[]
}

export interface PurgeBusinessDataResponse {
  businessId: string
  entities: PurgeBusinessDataEntity[]
  status: 'ok' | 'partial' | 'noop'
  message: string
  results?: Partial<Record<PurgeBusinessDataEntity, PurgeEntityResult>>
}

export interface CreateBusinessPayload {
  name: string
  nameFa: string
  about?: string
  slug?: string
  categoryIds: number[]
  ownerFirstName: string
  ownerLastName: string
  ownerFirstNameEn: string
  ownerLastNameEn: string
  ownerCellNumber: string
  ownerPassword: string
}

export interface BusinessesListResponse {
  items: BusinessListItem[]
  total: number
  page: number
  pageSize: number
}

