// Common types
export interface PaginatedResult<T> {
  items: T[]
  total: number
  page: number
  pageSize: number
}

// Auth types
export interface LoginRequest {
  username: string
  password: string
}

export interface LoginResponse {
  accessToken: string
  user: User
}

export interface User {
  id: string
  username: string
  email?: string
}

// Good types
export interface Good {
  id: string
  goodName: string
  goodImage: string | null
  goodPriority: number
  originGoodId: string
  originGood?: OriginGood
  countryId: string
  country?: Country
  categoryId: string
  category?: Category
  tagId?: string
  tag?: Tag
  tags: Tag[]
  positionId?: string
  position?: Position
  createdAt: string
  updatedAt: string
}

export interface CreateGoodRequest {
  goodName: string
  goodImage?: string
  originGoodId: number
  countryId: number
  categoryId: number
  tagIds?: number[]
  positionId?: number
  goodPriority?: number
}

export interface UpdateGoodRequest {
  goodName?: string
  goodImage?: string | null
  originGoodId?: number
  countryId?: number
  categoryId?: number
  tagIds?: number[]
  positionId?: number | null
  goodPriority?: number
}

export interface BatchCreateItem {
  originGoodId: number
  priority?: number
}

export interface BatchCreateGoodsRequest {
  items: BatchCreateItem[]
  countryId: number
  categoryId: number
  tagIds?: number[]
  positionId?: number
  defaultPriority?: number
}

export interface UpdatePriorityRequest {
  goodIds: string[]
  priority: number
}

// Country types
export interface Country {
  id: string
  countryName: string
  countryIcon?: string | null
  createdAt: string
  updatedAt: string
}

export interface CreateCountryRequest {
  countryName: string
  countryIcon?: string
}

export interface UpdateCountryRequest {
  countryName?: string
  countryIcon?: string | null
}

// Category types
export interface Category {
  id: string
  categoryName: string
  categoryIcon?: string | null
  sdsCategoryId?: string | null
  parentCategoryId?: string | null
  parent?: Category
  children?: Category[]
  _count?: {
    children: number
  }
  createdAt: string
  updatedAt: string
}

export interface CreateCategoryRequest {
  categoryName: string
  categoryIcon?: string
  parentCategoryId?: number
}

export interface UpdateCategoryRequest {
  categoryName?: string
  categoryIcon?: string | null
  parentCategoryId?: number | null
}

export interface CategoryTree extends Category {
  children?: CategoryTree[]
}

// Tag types
export interface Tag {
  id: string
  tagName: string
  tagColor?: string | null
  tagFontColor?: string | null
  timing?: string | null
  tagGroupId?: string | null
  sortOrder?: number
  tagGroup?: TagGroup | null
  createdAt: string
  updatedAt: string
}

export interface CreateTagRequest {
  tagName: string
  tagColor?: string
  tagFontColor?: string
  timing?: string
  tagGroupId?: number
  sortOrder?: number
}

export interface UpdateTagRequest {
  tagName?: string
  tagColor?: string | null
  tagFontColor?: string | null
  timing?: string | null
  tagGroupId?: number | null
  sortOrder?: number
}

// Tag Group types
export interface TagGroup {
  id: string
  groupName: string
  groupIcon?: string | null
  groupColor?: string | null
  sortOrder: number
  createdAt: string
  updatedAt: string
  _count?: { tags: number }
}

export interface CreateTagGroupRequest {
  groupName: string
  groupIcon?: string
  groupColor?: string
  sortOrder?: number
}

export interface UpdateTagGroupRequest {
  groupName?: string
  groupIcon?: string | null
  groupColor?: string | null
  sortOrder?: number
}

export interface ReorderTagGroupsRequest {
  items: Array<{ id: number; sortOrder: number }>
}

export interface ReorderTagsRequest {
  items: Array<{ id: number; tagGroupId?: number | null; sortOrder: number }>
}

// Position types
export interface Position {
  id: string
  indexVal: number
  countryId?: string
  country?: Country
  categoryId?: string
  category?: Category
  createdAt: string
  updatedAt: string
}

export interface CreatePositionRequest {
  indexVal: number
  countryId?: number
  categoryId?: number
}

export interface UpdatePositionRequest {
  indexVal?: number
  countryId?: number | null
  categoryId?: number | null
}

// Origin Good types
export interface OriginGood {
  id: string
  goodName: string | null
  goodImage: string | null
  goodPrice: string | null
  sdsGoodId: string
  sdsCategoryId: string | null
  createdAt: string
  updatedAt: string
}

// Origin Goods Tree types
export interface OriginGoodsTreeNode {
  id: string
  goodName: string
  goodImage: string | null
  goodPrice: string | null
  sdsGoodId: string
  configuredCount: number
  configuredCountries: string[]
  configuredTags: { tagName: string; tagColor: string | null; tagFontColor: string | null; tagGroupId: string | null; tagGroupName: string | null; sortOrder: number }[]
}

export interface OriginGoodsTreeCategoryNode {
  categoryId: string
  categoryName: string
  sdsCategoryId: string | null
  configuredCount: number
  totalCount: number
  children: OriginGoodsTreeCategoryNode[]
  originGoods: OriginGoodsTreeNode[]
}

export interface OriginGoodsTreeResponse {
  tree: OriginGoodsTreeCategoryNode[]
  totalOriginGoods: number
  configuredCount: number
}

// Sync types
export interface SyncLog {
  id: string
  type: 'CATEGORY' | 'PRODUCT'
  status: 'SUCCESS' | 'FAILED'
  message?: string
  startTime: string
  endTime?: string
  errorCount?: number
  createdAt: string
}

// Filter types
export interface GoodsFilter {
  countryId?: string
  categoryId?: string
  tagId?: string
  keyword?: string
  page?: number
  pageSize?: number
}

export interface CategoryFilter {
  parentCategoryId?: string
  categoryName?: string
  page?: number
  pageSize?: number
}

export interface CountryFilter {
  countryName?: string
  page?: number
  pageSize?: number
}

export interface TagFilter {
  tagName?: string
  page?: number
  pageSize?: number
}

export interface PositionFilter {
  countryId?: string
  categoryId?: string
  page?: number
  pageSize?: number
}
