declare namespace Api {
  /** 租户管理类型 */
  namespace Tenant {
    /** 租户状态枚举 */
    enum TenantStatus {
      PendingReview = 0,
      Active = 1,
      Suspended = 2,
      Expired = 3,
      Closed = 4
    }

    /** 租户认证状态枚举 */
    enum TenantVerificationStatus {
      Draft = 0,
      Pending = 1,
      Approved = 2,
      Rejected = 3
    }

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

    /** 租户信息 */
    interface TenantDto {
      id: string // long -> string
      code: string
      name: string
      shortName: string
      industry?: string
      contactName: string
      contactPhone: string
      contactEmail: string
      status: TenantStatus
      verificationStatus: TenantVerificationStatus
      operatingMode?: OperatingMode
      currentPackageId?: string // long -> string
      effectiveFrom?: string
      effectiveTo?: string
      autoRenew: boolean
    }

    /** 租户列表查询参数 */
    interface TenantListParams extends Common.PageParams {
      Status?: TenantStatus
      VerificationStatus?: TenantVerificationStatus
      Name?: string
      ContactName?: string
      ContactPhone?: string
      Keyword?: string
    }

    /** 租户列表响应 */
    type TenantListResponse = Common.PageResult<TenantDto>

    /** 注册租户命令 */
    interface RegisterTenantCommand {
      code: string
      name: string
      shortName?: string
      industry?: string
      contactName?: string
      contactPhone?: string
      contactEmail?: string
      tenantPackageId: string // long -> string
      durationMonths: number
      autoRenew: boolean
      effectiveFrom?: string
    }

    /** 后台手动新增租户命令（直接入驻） */
    interface CreateTenantManuallyCommand {
      // 1. 租户信息（public.tenants）
      code: string
      name: string
      shortName?: string
      legalEntityName?: string
      industry?: string
      logoUrl?: string
      coverImageUrl?: string
      website?: string
      country?: string
      province?: string
      city?: string
      address?: string
      contactName?: string
      contactPhone?: string
      contactEmail?: string
      tags?: string
      remarks?: string
      suspendedAt?: string | Date
      suspensionReason?: string
      tenantStatus: TenantStatus

      // 2. 订阅信息（public.tenant_subscriptions）
      tenantPackageId: string // long -> string
      durationMonths: number
      autoRenew: boolean
      subscriptionEffectiveFrom?: string | Date
      nextBillingDate?: string | Date
      subscriptionStatus?: number
      scheduledPackageId?: string // long -> string
      subscriptionNotes?: string

      // 3. 认证信息（public.tenant_verification_profiles）
      verificationStatus?: TenantVerificationStatus
      businessLicenseNumber?: string
      businessLicenseUrl?: string
      legalPersonName?: string
      legalPersonIdNumber?: string
      legalPersonIdFrontUrl?: string
      legalPersonIdBackUrl?: string
      bankAccountName?: string
      bankAccountNumber?: string
      bankName?: string
      additionalDataJson?: string
      submittedAt?: string | Date
      reviewedAt?: string | Date
      reviewedByName?: string
      reviewRemarks?: string

      // 4. 管理员账号（identity.identity_users）
      adminAccount: string
      adminDisplayName: string
      adminPassword: string
      adminAvatar?: string
      adminMerchantId?: string // long -> string
    }

    /** 自助注册租户命令 */
    interface SelfRegisterTenantCommand {
      adminAccount: string
      adminDisplayName?: string
      adminEmail?: string
      adminPhone: string
      adminPassword: string
    }

    /** 自助注册结果 */
    interface SelfRegisterResult {
      tenantId: string // long -> string
      code?: string
      status: TenantStatus
      verificationStatus: TenantVerificationStatus
      effectiveFrom?: string
      effectiveTo?: string
      adminAccount?: string
    }

    /** 入驻进度信息 */
    interface TenantProgress {
      tenantId: string // long -> string
      code?: string
      status: TenantStatus
      verificationStatus: TenantVerificationStatus
      effectiveFrom?: string
      effectiveTo?: string
    }

    /** 自助实名提交命令 */
    interface SubmitTenantVerificationCommand {
      tenantId: string // long -> string
      businessLicenseNumber?: string
      businessLicenseUrl?: string
      legalPersonName?: string
      legalPersonIdNumber?: string
      legalPersonIdFrontUrl?: string
      legalPersonIdBackUrl?: string
      bankAccountName?: string
      bankAccountNumber?: string
      bankName?: string
      additionalDataJson?: string
    }

    /** 租户套餐类型枚举 */
    enum TenantPackageType {
      Free = 0,
      Standard = 1,
      Professional = 2,
      Enterprise = 3
    }

    /** 套餐发布状态 */
    enum TenantPackagePublishStatus {
      Draft = 0,
      Published = 1
    }

    /** 租户套餐信息 */
    interface TenantPackageDto {
      id: string // long -> string
      name: string
      description?: string
      packageType: TenantPackageType
      monthlyPrice?: number
      yearlyPrice?: number
      maxStoreCount?: number
      maxAccountCount?: number
      maxStorageGb?: number
      maxSmsCredits?: number
      maxDeliveryOrders?: number
      featurePoliciesJson?: string
      isActive: boolean
      isPublicVisible: boolean
      isAllowNewTenantPurchase: boolean
      publishStatus: TenantPackagePublishStatus
      isRecommended: boolean
      tags: string[]
      sortOrder: number
    }

    /** 租户套餐列表查询参数 */
    interface TenantPackageQueryParams extends Common.PageParams {
      Keyword?: string
      IsActive?: boolean
    }

    /** 租户套餐列表响应 */
    type TenantPackageListResponse = Common.PageResult<TenantPackageDto>

    /** 公共租户套餐列表响应（匿名） */
    interface PublicTenantPackageListResponse {
      pageIndex: number
      pageSize: number
      totalCount: number
      items: TenantPackageDto[]
    }

    /** 创建租户套餐参数 */
    interface CreateTenantPackageCommand {
      name: string
      description?: string
      packageType: TenantPackageType
      monthlyPrice?: number
      yearlyPrice?: number
      maxStoreCount?: number
      maxAccountCount?: number
      maxStorageGb?: number
      maxSmsCredits?: number
      maxDeliveryOrders?: number
      featurePoliciesJson?: string
      isActive: boolean
      isPublicVisible: boolean
      isAllowNewTenantPurchase: boolean
      publishStatus: TenantPackagePublishStatus
      isRecommended: boolean
      tags: string[]
      sortOrder: number
    }

    /** 更新租户套餐参数 */
    interface UpdateTenantPackageCommand extends CreateTenantPackageCommand {
      tenantPackageId: string // long -> string
    }

    /** 套餐使用统计 */
    interface TenantPackageUsageDto {
      tenantPackageId: string // long -> string
      activeSubscriptionCount: number
      activeTenantCount: number
      totalSubscriptionCount: number
      mrr: number
      arr: number
      expiringTenantCount7Days: number
      expiringTenantCount15Days: number
      expiringTenantCount30Days: number
    }

    /** 套餐当前使用租户 */
    interface TenantPackageTenantDto {
      tenantId: string // long -> string
      code: string
      name: string
      status: TenantStatus
      contactName?: string
      contactPhone?: string
      subscriptionEffectiveFrom: string
      subscriptionEffectiveTo: string
    }

    /** 订阅状态枚举 */
    enum SubscriptionStatus {
      Active = 0,
      Expired = 1,
      Cancelled = 2,
      Suspended = 3
    }

    /** 租户订阅信息 */
    interface TenantSubscriptionDto {
      id: string // long -> string
      tenantId: string // long -> string
      tenantPackageId: string // long -> string
      status: SubscriptionStatus
      effectiveFrom: string
      effectiveTo: string
      nextBillingDate?: string
      autoRenew: boolean
    }

    /** 创建订阅命令 */
    interface CreateTenantSubscriptionCommand {
      tenantId: string // long -> string
      tenantPackageId: string // long -> string
      durationMonths?: number
      autoRenew?: boolean
      notes?: string
    }

    /** 延期/赠送订阅命令（按当前订阅续费） */
    interface ExtendTenantSubscriptionCommand {
      tenantId: string // long -> string
      durationMonths: number
      notes?: string
    }

    /** 初次绑定订阅命令（自助入驻） */
    interface BindInitialTenantSubscriptionCommand {
      tenantId: string // long -> string
      tenantPackageId: string // long -> string
      autoRenew?: boolean
    }

    /** 订阅升降配命令 */
    interface ChangeTenantSubscriptionPlanCommand {
      tenantId: string // long -> string
      tenantSubscriptionId: string // long -> string
      targetPackageId: string // long -> string
      immediate?: boolean
      notes?: string
    }

    /** 租户认证信息 */
    interface TenantVerificationDto {
      id: string // long -> string
      tenantId: string // long -> string
      status: TenantVerificationStatus
      businessLicenseNumber?: string
      businessLicenseUrl?: string
      legalPersonName?: string
      legalPersonIdNumber?: string
      legalPersonIdFrontUrl?: string
      legalPersonIdBackUrl?: string
      bankAccountName?: string
      bankAccountNumber?: string
      bankName?: string
      additionalDataJson?: string
      submittedAt?: string
      reviewedBy?: string // long -> string
      reviewRemarks?: string
      reviewedByName?: string
      reviewedAt?: string
    }

    /** 租户详情信息 */
    interface TenantDetailDto {
      tenant: TenantDto
      verification: TenantVerificationDto
      subscription: TenantSubscriptionDto
      package: TenantPackageDto
    }

    /** 租户审核日志 */
    interface TenantAuditLogDto {
      id: string // long -> string
      tenantId: string // long -> string
      action: number
      title: string
      description?: string
      operatorName?: string
      previousStatus?: TenantStatus
      currentStatus?: TenantStatus
      createdAt: string
    }

    /** 租户审核日志分页 */
    type TenantAuditLogListResponse = Common.PageResult<TenantAuditLogDto>

    /** 审核租户命令 */
    interface ReviewTenantCommand {
      tenantId: string // long -> string
      approve: boolean
      reason?: string
      renewMonths?: number
      operatingMode?: OperatingMode
    }

    /** 冻结租户命令 */
    interface FreezeTenantCommand {
      tenantId: string // long -> string
      reason: string
    }

    /** 解冻租户命令 */
    interface UnfreezeTenantCommand {
      tenantId: string // long -> string
      reason?: string
    }

    /** 租户审核领取信息 */
    interface TenantReviewClaimDto {
      id: string // long -> string
      tenantId: string // long -> string
      claimedBy: string // long -> string
      claimedByName: string
      claimedAt: string
    }
  }
}
