/**
 * 业务相关类型定义
 */

// 用户相关类型
declare namespace User {
  /** 用户状态 */
  type Status = 'active' | 'inactive' | 'banned';
  
  /** 用户性别 */
  type Gender = 'male' | 'female' | 'unknown';
  
  /** 用户角色 */
  interface Role extends BaseEntity {
    roleCode: string;
    roleName: string;
    description?: string;
    permissions?: Permission[];
  }
  
  /** 用户权限 */
  interface Permission extends BaseEntity {
    authority: string;
    description?: string;
  }
  
  /** 用户基础信息 */
  interface BaseInfo extends BaseEntity {
    userId: ID;
    username: string;
    nickname?: string;
    realName?: string;
    avatar?: string;
    avatarUrl?: string;
    phone?: string;
    email?: string;
    gender?: Gender;
    sexName?: string;
    birthday?: string;
    status: Status;
    tenantId?: ID;
    companyId?: ID;
  }
  
  /** 完整用户信息 */
  interface Info extends BaseInfo {
    roles?: Role[];
    authorities?: Permission[];
    balance?: number;
    points?: number;
    openid?: string;
    certification?: boolean;
    isAdmin?: boolean;
    lastLoginTime?: string;
  }
  
  /** 用户登录参数 */
  interface LoginParams {
    username?: string;
    password?: string;
    phone?: string;
    code?: string;
    captcha?: string;
    tenantId?: ID;
  }
  
  /** 用户注册参数 */
  interface RegisterParams {
    username: string;
    password: string;
    phone: string;
    code: string;
    nickname?: string;
    tenantId?: ID;
  }
}

// 商品相关类型
declare namespace Product {
  /** 商品状态 */
  type Status = 'draft' | 'published' | 'offline' | 'deleted';
  
  /** 商品规格 */
  interface Spec {
    specName: string;
    specValues: string[];
  }
  
  /** 商品SKU */
  interface SKU extends BaseEntity {
    skuId: ID;
    goodsId: ID;
    sku: string;
    price: number;
    originalPrice?: number;
    stock: number;
    weight?: number;
    volume?: number;
    image?: string;
    barcode?: string;
  }
  
  /** 商品分类 */
  interface Category extends BaseEntity, BaseTreeNode<Category> {
    categoryName: string;
    categoryCode?: string;
    description?: string;
    image?: string;
    sort?: number;
    status: Status;
  }
  
  /** 商品基础信息 */
  interface BaseInfo extends BaseEntity {
    goodsId: ID;
    goodsName: string;
    goodsCode?: string;
    categoryId: ID;
    categoryName?: string;
    brand?: string;
    description?: string;
    content?: string;
    images?: string[];
    mainImage?: string;
    status: Status;
    sort?: number;
    tags?: string[];
  }
  
  /** 完整商品信息 */
  interface Info extends BaseInfo {
    category?: Category;
    specs?: Spec[];
    skus?: SKU[];
    minPrice?: number;
    maxPrice?: number;
    totalStock?: number;
    salesCount?: number;
    viewCount?: number;
    favoriteCount?: number;
  }
  
  /** 商品查询参数 */
  interface QueryParams extends BasePaginationParams {
    categoryId?: ID;
    categoryIds?: ID[];
    keywords?: string;
    status?: Status;
    minPrice?: number;
    maxPrice?: number;
    brand?: string;
    tags?: string[];
    sortBy?: 'price' | 'sales' | 'createTime' | 'updateTime';
  }
}

// 订单相关类型
declare namespace Order {
  /** 订单状态 */
  type Status = 'pending' | 'paid' | 'shipped' | 'delivered' | 'completed' | 'cancelled' | 'refunded';
  
  /** 支付状态 */
  type PayStatus = 0 | 1 | 2; // 0-未支付 1-已支付 2-已退款
  
  /** 配送状态 */
  type DeliveryStatus = 10 | 20 | 30; // 10-待发货 20-已发货 30-已收货
  
  /** 支付方式 */
  type PaymentType = 0 | 1 | 2 | 3; // 0-余额 1-微信 2-支付宝 3-其他
  
  /** 订单商品 */
  interface Goods extends BaseEntity {
    orderGoodsId: ID;
    orderId: ID;
    goodsId: ID;
    goodsName: string;
    goodsImage?: string;
    skuId?: ID;
    sku?: string;
    price: number;
    quantity: number;
    totalPrice: number;
    refundQuantity?: number;
    refundAmount?: number;
  }
  
  /** 收货地址 */
  interface Address {
    name: string;
    phone: string;
    province: string;
    city: string;
    district: string;
    detail: string;
    postalCode?: string;
  }
  
  /** 订单基础信息 */
  interface BaseInfo extends BaseEntity {
    orderId: ID;
    orderNo: string;
    userId: ID;
    status: Status;
    payStatus: PayStatus;
    deliveryStatus?: DeliveryStatus;
    paymentType?: PaymentType;
    totalAmount: number;
    payAmount: number;
    discountAmount?: number;
    shippingFee?: number;
    remark?: string;
    payTime?: string;
    shipTime?: string;
    deliveryTime?: string;
    completeTime?: string;
    cancelTime?: string;
  }
  
  /** 完整订单信息 */
  interface Info extends BaseInfo {
    goods?: Goods[];
    address?: Address;
    user?: User.BaseInfo;
    goodsCount?: number;
    trackingNumber?: string;
    expressCompany?: string;
  }
  
  /** 订单创建参数 */
  interface CreateParams {
    goods: Array<{
      goodsId: ID;
      skuId?: ID;
      quantity: number;
      price?: number;
    }>;
    address: Address;
    paymentType: PaymentType;
    remark?: string;
    couponId?: ID;
    usePoints?: number;
  }
  
  /** 订单查询参数 */
  interface QueryParams extends BasePaginationParams {
    userId?: ID;
    status?: Status;
    payStatus?: PayStatus;
    deliveryStatus?: DeliveryStatus;
    orderNo?: string;
    startTime?: string;
    endTime?: string;
  }
}

// 购物车相关类型
declare namespace Cart {
  /** 购物车商品 */
  interface Item {
    cartId: ID;
    goodsId: ID;
    goodsName: string;
    goodsImage?: string;
    skuId?: ID;
    sku?: string;
    price: number;
    originalPrice?: number;
    quantity: number;
    stock: number;
    selected: boolean;
    invalid?: boolean;
    addTime: string;
  }
  
  /** 购物车统计 */
  interface Summary {
    totalCount: number;
    selectedCount: number;
    totalAmount: number;
    selectedAmount: number;
    discountAmount?: number;
    finalAmount: number;
  }
}

// 内容管理相关类型
declare namespace CMS {
  /** 文章状态 */
  type ArticleStatus = 'draft' | 'published' | 'archived';
  
  /** 文章分类 */
  interface Category extends BaseEntity, BaseTreeNode<Category> {
    categoryName: string;
    categoryCode?: string;
    description?: string;
    image?: string;
    sort?: number;
  }
  
  /** 文章信息 */
  interface Article extends BaseEntity {
    articleId: ID;
    title: string;
    summary?: string;
    content: string;
    coverImage?: string;
    categoryId?: ID;
    categoryName?: string;
    author?: string;
    status: ArticleStatus;
    publishTime?: string;
    viewCount?: number;
    likeCount?: number;
    tags?: string[];
    seoTitle?: string;
    seoKeywords?: string;
    seoDescription?: string;
  }
  
  /** 文章查询参数 */
  interface ArticleQueryParams extends BasePaginationParams {
    categoryId?: ID;
    status?: ArticleStatus;
    keywords?: string;
    author?: string;
    tags?: string[];
    startTime?: string;
    endTime?: string;
  }
}

// 系统相关类型
declare namespace System {
  /** 字典类型 */
  interface Dict extends BaseEntity {
    dictCode: string;
    dictName: string;
    dictValue: string;
    description?: string;
    sort?: number;
    status?: 'active' | 'inactive';
  }
  
  /** 配置项 */
  interface Config extends BaseEntity {
    configKey: string;
    configValue: string;
    configName?: string;
    description?: string;
    type?: 'string' | 'number' | 'boolean' | 'json';
  }
  
  /** 菜单项 */
  interface Menu extends BaseEntity, BaseTreeNode<Menu> {
    menuName: string;
    menuCode?: string;
    path?: string;
    icon?: string;
    component?: string;
    permission?: string;
    sort?: number;
    visible?: boolean;
    type?: 'menu' | 'button';
  }
}
