// 授权管理类型定义

/**
 * 角色类型
 */
export type RoleType =
  | 'COMMUNITY'
  | 'AUTH_PROVINCE_COMPANY'
  | 'PROVINCE_COMPANY'
  | 'AUTH_CITY_COMPANY'
  | 'CITY_COMPANY';

/**
 * 授权状态
 */
export type AuthorizationStatus = 'AUTHORIZED' | 'REVOKED';

/**
 * 授权信息
 */
export interface Authorization {
  id: string;
  accountSequence: string;
  nickname: string;
  avatar: string | null;
  roleType: RoleType;
  regionName: string;
  status: AuthorizationStatus;
  benefitActive: boolean;
  officePhotoUrls: string[];
  createdAt: string;
  authorizedAt: string | null;
  revokedAt: string | null;
  revokeReason: string | null;
}

/**
 * 查询授权列表参数
 */
export interface QueryAuthorizationsParams {
  roleType?: RoleType;
  keyword?: string;
  includeRevoked?: boolean;
  page?: number;
  limit?: number;
}

/**
 * 授权列表响应
 */
export interface AuthorizationListResponse {
  items: Authorization[];
  total: number;
  page: number;
  limit: number;
}

/**
 * 撤销授权请求
 */
export interface RevokeAuthorizationRequest {
  reason: string;
}

/**
 * 授权社区请求
 */
export interface GrantCommunityRequest {
  userId: string;
  accountSequence: string;
  communityName: string;
  skipAssessment?: boolean;
}

/**
 * 授权省公司请求
 */
export interface GrantProvinceCompanyRequest {
  userId: string;
  accountSequence: string;
  provinceCode: string;
  provinceName: string;
  skipAssessment?: boolean;
}

/**
 * 授权市公司请求
 */
export interface GrantCityCompanyRequest {
  userId: string;
  accountSequence: string;
  cityCode: string;
  cityName: string;
  skipAssessment?: boolean;
}

/**
 * 授权省团队请求
 */
export interface GrantAuthProvinceCompanyRequest {
  userId: string;
  accountSequence: string;
  provinceCode: string;
  provinceName: string;
  skipAssessment?: boolean;
}

/**
 * 授权市团队请求
 */
export interface GrantAuthCityCompanyRequest {
  userId: string;
  accountSequence: string;
  cityCode: string;
  cityName: string;
  skipAssessment?: boolean;
}

/**
 * 角色类型显示名称
 */
export const ROLE_TYPE_LABELS: Record<RoleType, string> = {
  COMMUNITY: '社区',
  AUTH_PROVINCE_COMPANY: '省团队',
  PROVINCE_COMPANY: '正式省公司',
  AUTH_CITY_COMPANY: '市团队',
  CITY_COMPANY: '正式市公司',
};

/**
 * 获取角色类型显示名称
 */
export function getRoleTypeLabel(roleType: RoleType): string {
  return ROLE_TYPE_LABELS[roleType] || roleType;
}

/**
 * 角色类型筛选选项
 */
export const ROLE_TYPE_OPTIONS = [
  { value: 'COMMUNITY', label: '社区' },
  { value: 'AUTH_PROVINCE_COMPANY', label: '省团队' },
  { value: 'PROVINCE_COMPANY', label: '正式省公司' },
  { value: 'AUTH_CITY_COMPANY', label: '市团队' },
  { value: 'CITY_COMPANY', label: '正式市公司' },
] as const;
