import { GraphQLJSONObject } from './scalars.js';
import { listPlaces, listVoiceExperiences } from './places.js';
import { createVoiceExperience } from './voice-experiences.js';

export const schema = /* GraphQL */ `
  scalar JSON

  enum VoiceExperienceStatus {
    UPLOADED
    TRANSCRIBING
    TRANSCRIBED
    ANALYZING
    ANALYZED
    FAILED
  }

  type Place {
    id: ID!
    googlePlaceId: String!
    name: String!
    latitude: Float!
    longitude: Float!
    experiences: [VoiceExperience!]!
  }

  type VoiceExperience {
    id: ID!
    place: Place!
    status: VoiceExperienceStatus!
    durationSeconds: Int!
    audioObjectKey: String!
    transcript: String
    analysis: JSON
    createdAt: String!
  }

  input CreateVoiceExperienceInput {
    googlePlaceId: String!
    googleName: String!
    latitude: Float!
    longitude: Float!
    durationSeconds: Int!
    audioObjectKey: String!
  }

  type Query {
    health: String!
    places: [Place!]!
    voiceExperiences: [VoiceExperience!]!
  }

  type Mutation {
    createVoiceExperience(input: CreateVoiceExperienceInput!): VoiceExperience!
  }
`;

export const resolvers = {
  JSON: GraphQLJSONObject,
  Query: {
    health: () => 'ok',
    places: () => listPlaces(),
    voiceExperiences: () => listVoiceExperiences(),
  },
  Mutation: {
    createVoiceExperience: async (
      _: unknown,
      args: { input: Parameters<typeof createVoiceExperience>[0] },
    ) => createVoiceExperience(args.input),
  },
};
