import { google } from 'googleapis'

const SCOPES = ['https://www.googleapis.com/auth/calendar']

/**
 * Cliente de Google Calendar usando Service Account.
 * Accede al calendario de la barbería sin requerir que el dueño
 * autorice cada vez.
 */
export function getCalendarClient() {
  const auth = new google.auth.GoogleAuth({
    credentials: {
      client_email: process.env.GOOGLE_SERVICE_ACCOUNT_EMAIL!,
      private_key: process.env.GOOGLE_SERVICE_ACCOUNT_PRIVATE_KEY!.replace(/\\n/g, '\n'),
    },
    scopes: SCOPES,
  })

  return google.calendar({ version: 'v3', auth })
}

export const CALENDAR_ID = process.env.GOOGLE_CALENDAR_ID!
