import { DefaultSession, DefaultUser } from 'next-auth'
import { JWT, DefaultJWT } from 'next-auth/jwt'

export enum UserRole {
  USER = 'USER',
  GROWER = 'GROWER',
  FARM_MANAGER = 'FARM_MANAGER',
  ADMIN = 'ADMIN',
}

export interface AuthUser {
  id: string
  email: string
  name?: string | null
  image?: string | null
  role: UserRole
  emailVerified?: Date | null
}

declare module 'next-auth' {
  interface Session extends DefaultSession {
    user: AuthUser
  }

  interface User extends DefaultUser {
    role: UserRole
    emailVerified?: Date | null
  }
}

declare module 'next-auth/jwt' {
  interface JWT extends DefaultJWT {
    id: string
    role: UserRole
    emailVerified?: Date | null
  }
}

export interface RegisterInput {
  email: string
  password: string
  name?: string
  role?: UserRole
}

export interface LoginInput {
  email: string
  password: string
}

export interface ForgotPasswordInput {
  email: string
}

export interface ResetPasswordInput {
  token: string
  password: string
}

export interface VerifyEmailInput {
  token: string
}

export interface AuthResponse {
  success: boolean
  message: string
  user?: AuthUser
  error?: string
}

export interface TokenPayload {
  userId: string
  email: string
  type: 'email_verification' | 'password_reset'
  expiresAt: number
}
