import { defineDb, defineTable, column } from 'astro:db';

const ConsentLog = defineTable({
  columns: {
    id: column.number({ primaryKey: true }),
    action: column.text(),
    purpose: column.text(),
    analytics: column.boolean({ default: false }),
    marketing: column.boolean({ default: false }),
    functional: column.boolean({ default: false }),
    userAgent: column.text({ optional: true }),
    ip: column.text({ optional: true }),
    timestamp: column.date(),
    sessionId: column.text({ optional: true }),
  },
});

export type ConsentAction = 'accept' | 'reject' | 'update';
export type ConsentPurpose = 'analytics' | 'marketing' | 'functional' | 'all';

export interface ConsentRow {
  id: number;
  action: ConsentAction;
  purpose: ConsentPurpose;
  analytics: boolean;
  marketing: boolean;
  functional: boolean;
  userAgent?: string;
  ip?: string;
  timestamp: Date;
  sessionId?: string;
}

export default defineDb({
  tables: {
    ConsentLog,
  },
});