interface ApiKey {
  id: string;
  name: string;
  prefix: string;
  created: string;
  lastUsed: string;
  status: 'active' | 'revoked';
  scopes: string[];
}

const MOCK_KEYS: ApiKey[] = [
  {
    id: 'k1',
    name: 'Production App',
    prefix: 'vz_8x92...',
    created: 'Oct 10, 2023',
    lastUsed: '2 mins ago',
    status: 'active',
    scopes: ['read', 'write'],
  },
  {
    id: 'k2',
    name: 'Test Environment',
    prefix: 'vz_9a21...',
    created: 'Sep 15, 2023',
    lastUsed: '5 days ago',
    status: 'active',
    scopes: ['read'],
  },
];

export const developerService = {
  listKeys: async () => {
    await new Promise((resolve) => setTimeout(resolve, 500));
    return MOCK_KEYS;
  },

  createKey: async (data: { name: string; scopes: string[] }) => {
    await new Promise((resolve) => setTimeout(resolve, 800));
    return {
      id: `k-${Date.now()}`,
      name: data.name,
      prefix: `vz_${Math.random().toString(36).substr(2, 4)}...`,
      created: 'Just now',
      lastUsed: 'Never',
      status: 'active' as const,
      scopes: data.scopes,
    };
  },

  revokeKey: async (_id: string) => {
    await new Promise((resolve) => setTimeout(resolve, 400));
    return { success: true };
  },

  getStats: async () => {
    await new Promise((resolve) => setTimeout(resolve, 400));
    return {
      requests_24h: 145200,
      avg_latency: 45,
      active_keys: MOCK_KEYS.length,
    };
  },
};
