"A date string with format `Y-m-d`, e.g. `2011-05-23`."
scalar Date @scalar(class: "Nuwave\\Lighthouse\\Schema\\Types\\Scalars\\Date")

"A datetime string with format `Y-m-d H:i:s`, e.g. `2018-05-23 13:43:32`."
scalar DateTime
    @scalar(class: "Nuwave\\Lighthouse\\Schema\\Types\\Scalars\\DateTime")

scalar Json @scalar(class: "MLL\\GraphQLScalars\\JSON")

type Category {
    id: ID!
    name: String!
    type: String!
    color: String
}

type Budget {
    id: ID!
    name: String!
    amount: Float!
    totalTransactionsAmount: Float!
    totalSpentPercentage: Float!
    TotalMarginPerDay: Float!
    isSaving: Boolean!
    startAtDate: String!
    endAtDate: String!
}

type Brand {
    id: ID!
    name: String!
    category: Category @belongsTo
    transactionsCount: Int! @count(relation: "transactions")
}

type Transaction {
    id: ID!
    amount: Float!
    brand: Brand! @belongsTo
    created_at: Date!
    note: String
}

type Sms {
    id: ID!
    body: String!
    transaction_id: Int
    meta: Json
}

input Message {
    role: String!
    content: String!
}

type Query {
    transactions(search: String @search): [Transaction!]!
        @paginate(defaultCount: 50)
        @lazyLoad(relations: ["brand"])
        @orderBy(column: id direction: DESC)

    allBrands: [Brand!]! @all
    budgets: [Budget!]! @all
    brands(search: String @search): [Brand!]!
        @paginate(defaultCount: 50)
        @lazyLoad(relations: ["category"])
        @orderBy(column: id direction: DESC)

    allCategories: [Category!]! @all
    categories(search: String @search): [Category!]!
        @paginate(defaultCount: 50)
        @orderBy(column: id direction: DESC)

    sms(search: String @search): [Sms!]!
        @paginate(defaultCount: 100)
        @orderBy(column: transaction_id direction: ASC)

    totalIncome(range: String!): Json
    totalExpenses(range: String!): Json
    totalSavings: Json
    totalInvestment: Json
    totalCash: Json
    netWorth: Json

    expensesPerCategory(range: String!): Json
    incomePerCategory(range: String!): Json
    totalPerBrand(range: String! category_id: Int): Json

    totalIncomeTrend(range: String!): Json
    totalExpensesTrend(range: String!): Json
    totalPerCategoryTrend(range: String! id: ID!): Json
    totalPerCategoryDailyTrend(range: String! id: ID!): Json
    totalPerBrandTrend(range: String! id: ID!): Json
    changeRatePerBrandTrend(range: String! id: ID!): Json

    numberOfTransactions(range: String!): Json
    numberOfTransactionsPerCategory(range: String!): Json
    numberOfTransactionsPerBrand(range: String! id: ID!): Json
    highestValueTransaction(range: String!): Json
    lowestValueTransaction(range: String!): Json
    averageValueTransaction(range: String!): Json
    transactionsStandardDeviation(range: String! id: ID!): Json
    financeVisualizationCirclePackMetric(range: String!): Json

    hisabiGPT(messages: [Message]): Json
}

type Mutation {
    createTransaction(
        amount: Float!
        brand_id: Int!
        created_at: String!
        note: String
    ): Transaction @create
    updateTransaction(
        id: ID!
        amount: Float!
        brand_id: Int!
        created_at: String!
        note: String
    ): Transaction @update
    deleteTransaction(id: ID! @whereKey): Transaction @delete

    createBrand(name: String! category_id: Int!): Brand @create
    updateBrand(id: ID! name: String! category_id: Int!): Brand @update
    deleteBrand(id: ID! @whereKey): Brand @delete

    createCategory(name: String! type: String! color: String!): Category
        @create
    updateCategory(
        id: ID!
        name: String!
        type: String!
        color: String!
    ): Category @update
    deleteCategory(id: ID! @whereKey): Category @delete

    createSms(
        body: String!
        created_at: String
    ): [Sms]
    updateSms(id: ID! body: String!): Sms
    deleteSms(id: ID! @whereKey): Sms @delete
}
