export interface Project {
    id: string;
    name: string;
    maxConcurrentRuns: number;
    teamId: string;
    createdByUserId: string;
    createdAt: string;
    updatedAt: string;
    maxConcurrentRunsLimit?: number;
    _count?: {
        testCases: number;
    };
    hasActiveRuns?: boolean;
}

export type TeamRole = 'OWNER' | 'MEMBER';

export interface Team {
    id: string;
    name: string;
    role?: TeamRole;
    openRouterKeyUpdatedAt?: string | null;
    createdAt: string;
    updatedAt: string;
}

export interface TeamMembership {
    id: string;
    teamId: string;
    userId: string | null;
    email: string | null;
    role: TeamRole;
    createdAt: string;
    updatedAt: string;
}

export interface UsageRecord {
    id: string;
    actorUserId: string;
    projectId: string;
    type: string;
    description: string | null;
    aiActions: number;
    testRunId: string | null;
    createdAt: string;
}

export interface TestCase {
    id: string;
    displayId?: string;
    status?: TestStatus;
    name: string;
    url: string;
    prompt: string;
    steps?: TestStep[];
    browserConfig?: Record<string, BrowserConfig>;
    source?: string | null;
    sourceHash?: string | null;
    projectId: string;
    createdAt: string;
    updatedAt: string;
    testRuns?: TestRun[];
}

export interface LoginFlowPrefixInfo {
    runId: string;
    testCaseId: string;
    displayId: string | null;
    name: string;
    status: string;
}

export interface RunSessionMemberInfo {
    runId: string;
    testCaseId: string;
    displayId: string | null;
    name: string;
    kind: string;
    status: string;
    sessionPosition: number;
    reusedSession?: boolean;
}

export interface RunSessionInfo {
    id: string;
    kind: string;
    groupName: string | null;
    onFailure: string | null;
    members: RunSessionMemberInfo[];
}

export interface TestRun {
    id: string;
    testCaseId: string;
    triggeredByEmail?: string | null;
    triggerSource?: string | null;
    instanceId?: string | null;
    instanceType?: string | null;
    instanceName?: string | null;
    requiredCapability?: string | null;
    requiredRunnerKind?: string | null;
    requestedDeviceId?: string | null;
    requestedRunnerId?: string | null;
    assignedRunnerId?: string | null;
    leaseExpiresAt?: string | null;
    lastEventAt?: string | null;
    nextEventSequence?: number;
    status: TestStatus;
    result?: string;
    error?: string;
    slackNotifyError?: string | null;
    errorCode?: TestFailureCode;
    errorCategory?: TestFailureCategory;
    createdAt: string;
    events?: TestEvent[];
}

export interface Runner {
    id: string;
    displayId: string;
    hostFingerprint: string;
    teamId: string;
    label: string;
    kind: string;
    capabilities: string[];
    protocolVersion: string;
    runnerVersion: string;
    status: string;
    lastSeenAt: string;
    createdAt: string;
    updatedAt: string;
}

export interface RunnerToken {
    id: string;
    teamId: string;
    runnerId: string | null;
    createdByUserId: string | null;
    kind: string;
    prefix: string;
    expiresAt: string;
    revokedAt: string | null;
    consumedAt: string | null;
    lastUsedAt: string | null;
    createdAt: string;
}

export interface RunnerDevice {
    id: string;
    runnerId: string;
    deviceId: string;
    platform: string;
    name: string;
    state: string;
    metadata: Record<string, unknown> | null;
    lastSeenAt: string;
    createdAt: string;
    updatedAt: string;
}

export interface TestRunEventRow {
    id: string;
    runId: string;
    sequence: number;
    kind: string;
    message: string | null;
    payload: Record<string, unknown> | null;
    artifactKey: string | null;
    createdAt: string;
}

import type { TestStep, BrowserConfig, TestFailureCode, TestFailureCategory } from './test';
import type { TestStatus } from './status';
import type { TestEvent } from './events';
