export interface SaasTenant {
  id: string;
  code: string;
  name: string;
  type: 'SAAS' | 'ENTERPRISE' | 'TRIAL';
  status: 'ACTIVE' | 'SUSPENDED' | 'CANCELED';
  plan: 'BASIC' | 'PRO' | 'ENTERPRISE';
  maxUsers: number;
  maxShops: number;
  storageQuota: number;
  features: string[];
  config: Record<string, any>;
  expiresAt: Date | null;
  createdAt: Date;
  updatedAt: Date;
}

export interface TenantDomain {
  id: string;
  tenantId: string;
  domain: string;
  type: 'SUBDOMAIN' | 'CUSTOM_DOMAIN';
  status: 'ACTIVE' | 'PENDING' | 'VERIFIED' | 'ERROR';
  sslEnabled: boolean;
  sslExpiry: Date | null;
  primary: boolean;
  verifiedAt: Date | null;
  createdAt: Date;
  updatedAt: Date;
}

export interface TenantUser {
  id: string;
  tenantId: string;
  userId: string;
  role: 'ADMIN' | 'MANAGER' | 'OPERATOR' | 'VIEWER';
  permissions: string[];
  status: 'ACTIVE' | 'INACTIVE' | 'SUSPENDED';
  createdAt: Date;
  updatedAt: Date;
}

export interface TenantSettings {
  [key: string]: string;
}

export interface SaasTenantDataSource {
  list(filters?: {
    status?: string;
    plan?: string;
    type?: string;
  }): Promise<SaasTenant[]>;
  
  get(tenantId: string): Promise<SaasTenant | null>;
  
  create(data: {
    code: string;
    name: string;
    type?: 'SAAS' | 'ENTERPRISE' | 'TRIAL';
    plan?: 'BASIC' | 'PRO' | 'ENTERPRISE';
    maxUsers?: number;
    maxShops?: number;
    storageQuota?: number;
    features?: string[];
    config?: Record<string, any>;
    expiresAt?: Date;
  }): Promise<SaasTenant>;
  
  update(tenantId: string, data: {
    name?: string;
    plan?: 'BASIC' | 'PRO' | 'ENTERPRISE';
    maxUsers?: number;
    maxShops?: number;
    storageQuota?: number;
    features?: string[];
    config?: Record<string, any>;
    expiresAt?: Date;
  }): Promise<SaasTenant>;
  
  delete(tenantId: string): Promise<void>;
  
  updateStatus(tenantId: string, status: 'ACTIVE' | 'SUSPENDED' | 'CANCELED'): Promise<SaasTenant>;
  
  getDomains(tenantId: string): Promise<TenantDomain[]>;
  
  addDomain(tenantId: string, domain: string, type?: 'SUBDOMAIN' | 'CUSTOM_DOMAIN'): Promise<TenantDomain>;
  
  verifyDomain(domainId: string): Promise<TenantDomain>;
  
  setPrimaryDomain(domainId: string): Promise<void>;
  
  deleteDomain(domainId: string): Promise<void>;
  
  getUsers(tenantId: string): Promise<TenantUser[]>;
  
  addUser(tenantId: string, userId: string, role?: 'ADMIN' | 'MANAGER' | 'OPERATOR' | 'VIEWER', permissions?: string[]): Promise<TenantUser>;
  
  updateUserRole(tenantId: string, userId: string, role: 'ADMIN' | 'MANAGER' | 'OPERATOR' | 'VIEWER', permissions?: string[]): Promise<TenantUser>;
  
  removeUser(tenantId: string, userId: string): Promise<void>;
  
  getUserTenants(userId: string): Promise<Array<{ tenant: SaasTenant; user: TenantUser }>>;
  
  getSettings(tenantId: string, category?: string): Promise<TenantSettings>;
  
  getSetting(tenantId: string, key: string): Promise<string | null>;
  
  setSetting(tenantId: string, key: string, value: string, category?: string): Promise<void>;
  
  getCurrentTenant(): Promise<SaasTenant | null>;
  
  getStats(): Promise<{
    totalTenants: number;
    activeTenants: number;
    suspendedTenants: number;
    trialTenants: number;
    totalUsers: number;
    totalShops: number;
    totalDomains: number;
    storageUsed: number;
    storageTotal: number;
  }>;
  
  getUsage(tenantId: string): Promise<{
    userId: number;
    shopId: number;
    storageUsed: number;
    apiCalls: number;
    lastActive: Date;
  }>;
  
  getOperationLogs(tenantId: string): Promise<Array<{
    id: string;
    tenantId: string;
    tenantName: string;
    operation: string;
    operator: string;
    timestamp: Date;
    details: string;
  }>>;
  
  exportTenants(tenants: SaasTenant[]): Promise<void>;
}