declare namespace Api {
  /** 商户管理类型 */
  namespace Merchant {
    /** 商户状态枚举 */
    enum MerchantStatus {
      Pending = 0,
      Approved = 1,
      Rejected = 2,
      Frozen = 3
    }

    /** 经营模式枚举 */
    enum OperatingMode {
      SameEntity = 1,
      DifferentEntity = 2
    }

    /** 门店状态枚举 */
    enum StoreStatus {
      Closed = 0,
      Preparing = 1,
      Operating = 2,
      Suspended = 3
    }

    /** 审核动作枚举 */
    enum ReviewAction {
      ApplicationSubmitted = 0,
      DocumentUploaded = 1,
      DocumentReviewed = 2,
      ContractUpdated = 3,
      ContractStatusChanged = 4,
      MerchantReviewed = 5,
      ReviewClaimed = 6,
      ReviewReleased = 7,
      ReviewApproved = 8,
      ReviewRejected = 9,
      ReviewRevoked = 10,
      ReviewPendingReApproval = 11,
      ReviewForceClaimed = 12
    }

    /** 商户列表项 */
    interface MerchantListItem {
      id: string // long -> string
      tenantId: string // long -> string
      tenantName?: string
      name: string
      operatingMode?: OperatingMode
      licenseNumber?: string
      status: MerchantStatus
      isFrozen: boolean
      storeCount?: number
      createdAt: string
      updatedAt?: string
    }

    /** 商户审核列表项 */
    interface MerchantReviewListItem {
      id: string // long -> string
      tenantId: string // long -> string
      tenantName?: string
      name: string
      operatingMode?: OperatingMode
      licenseNumber?: string
      status: MerchantStatus
      claimedByName?: string
      claimedAt?: string | null
      claimExpiresAt?: string | null
      createdAt: string
    }

    /** 商户列表查询参数 */
    interface MerchantListParams extends Common.PageParams {
      keyword?: string
      status?: MerchantStatus
      operatingMode?: OperatingMode
      tenantId?: string // long -> string
      sortBy?: string
      sortOrder?: 'asc' | 'desc'
    }

    /** 商户列表响应 */
    type MerchantListResponse = Common.PageResult<MerchantListItem>

    /** 商户审核列表响应 */
    type MerchantReviewListResponse = Common.PageResult<MerchantReviewListItem>

    /** 门店列表项 */
    interface StoreListItem {
      id: string // long -> string
      name: string
      licenseNumber?: string | null
      contactPhone?: string
      address?: string
      status: StoreStatus
    }

    /** 商户详情 */
    interface MerchantDetail {
      id: string // long -> string
      tenantId: string // long -> string
      tenantName?: string
      name: string
      operatingMode?: OperatingMode
      licenseNumber?: string
      legalRepresentative?: string
      registeredAddress?: string
      contactPhone?: string
      contactEmail?: string
      status: MerchantStatus
      isFrozen: boolean
      frozenReason?: string | null
      frozenAt?: string | null
      approvedBy?: string | null // long -> string
      approvedAt?: string | null
      stores?: StoreListItem[]
      rowVersion?: string
      createdAt?: string
      createdBy?: string | null // long -> string
      updatedAt?: string | null
      updatedBy?: string | null // long -> string
    }

    /** 更新商户请求 */
    interface UpdateMerchantRequest {
      name?: string
      licenseNumber?: string
      legalRepresentative?: string
      registeredAddress?: string
      contactPhone?: string
      contactEmail?: string
      rowVersion: string
    }

    /** 更新商户响应 */
    interface UpdateMerchantResult {
      merchant: MerchantDetail
      requiresReview: boolean
    }

    /** 审核领取信息 */
    interface ClaimInfo {
      merchantId: string // long -> string
      claimedBy?: string // long -> string
      claimedByName?: string
      claimedAt?: string | null
      claimExpiresAt?: string | null
    }

    /** 审核记录 */
    interface MerchantAuditRecord {
      id: string // long -> string
      merchantId?: string // long -> string
      action: ReviewAction
      operatorId?: string | null // long -> string
      operatorName?: string | null
      ipAddress?: string | null
      title?: string
      description?: string | null
      createdAt: string
    }

    /** 变更记录 */
    interface MerchantChangeLogRecord {
      id: string // long -> string
      fieldName: string
      oldValue?: string | null
      newValue?: string | null
      changedBy?: string | null // long -> string
      changedByName?: string | null
      changedAt: string
      changeReason?: string | null
    }

    /** 审核请求 */
    interface ReviewMerchantRequest {
      approve: boolean
      remarks?: string
    }

    /** 撤销审核请求 */
    interface RevokeMerchantRequest {
      reason: string
    }
  }
}
