<% const vars = { 
  ModuleName: t.TheThing + 'Controller',
  ServiceName: t.TheThing + 'Service',
}; %>
---
outDir: <%= t.defaultOutDir %>
fileName: <%= t['the-thing'] + '-controller.ts' %>
sourceName: <%= vars.ModuleName %>
compiledName: <%= t.TheThing + 'RPC' %>
---

import { procedure, prefix, get, put, post, del, operation } from 'vovk';
import * as v from 'valibot';
import { toStandardJsonSchema } from '@valibot/to-json-schema';
<% if(t.withService) { %>
import <%= vars.ServiceName %> from './<%= t['the-thing'] %>-service<%= t.nodeNextResolutionExt.ts %>';
<% } %>

@prefix('<%= t['the-things'] %>')
export default class <%= vars.ModuleName %> {
    @operation({
      summary: 'Get <%= t.theThings %>',
    })
    @get()
    static get<%= t.TheThings %> = procedure().handle(() => {
        <% if(t.withService) { %>
        return <%= vars.ServiceName %>.get<%= t.TheThings %>();
        <% } else { %>
        return { message: 'TODO: get <%= t.theThings %>' };
        <% } %>
    });

    @operation({
        summary: 'Get single <%= t.theThing %>',
    })
    @get('{id}')
    static getSingle<%= t.TheThing %> = procedure({
        params: toStandardJsonSchema(v.object({ id: v.string() })),
    }).handle((_req, { id }) => {
        <% if(t.withService) { %>
        return <%= vars.ServiceName %>.getSingle<%= t.TheThing %>(id);
        <% } else { %>
        return { message: `TODO: get single <%= t.theThing %>`, id };
        <% } %>
    });

    @operation({
        summary: 'Update <%= t.theThing %>',
    })
    @put('{id}')
    static update<%= t.TheThing %> = procedure({
        body: toStandardJsonSchema(v.object({ todo: v.literal(true) })),
        params: toStandardJsonSchema(v.object({ id: v.string() })),
    }).handle(async (req, { id }) => {
        const body = await req.json();
        <% if(t.withService) { %>
        return <%= vars.ServiceName %>.update<%= t.TheThing %>(id, body);
        <% } else { %>
        return { message: `TODO: update <%= t.theThing %>`, id, body };
        <% } %>
    });

    @operation({
        summary: 'Create <%= t.theThing %>',
    })
    @post()
    static create<%= t.TheThing %> = procedure({
        body: toStandardJsonSchema(v.object({ todo: v.literal(true) })),
    }).handle(async (req) => {
        const body = await req.json();
        <% if(t.withService) { %>
        return <%= vars.ServiceName %>.create<%= t.TheThing %>(body);
        <% } else { %>
        return { message: `TODO: create <%= t.theThing %>`, body };
        <% } %>
    });

    @operation({
        summary: 'Delete <%= t.theThing %>',
    })
    @del('{id}')
    static delete<%= t.TheThing %> = procedure({
        params: toStandardJsonSchema(v.object({ id: v.string() })),
    }).handle((_req, { id }) => {
        <% if(t.withService) { %>
        return <%= vars.ServiceName %>.delete<%= t.TheThing %>(id);
        <% } else { %>
        return { message: `TODO: delete <%= t.theThing %>`, id };
        <% } %>
    });
}