module transaction.data;

import handy_http_primitives : Optional, ServerHttpRequest;
import std.datetime;

import transaction.model;
import transaction.dto;
import util.money;
import util.pagination;

interface TransactionVendorRepository {
    Optional!TransactionVendor findById(ulong id);
    TransactionVendor[] findAll();
    bool existsByName(string name);
    bool existsById(ulong id);
    TransactionVendor insert(string name, string description);
    void deleteById(ulong id);
    TransactionVendor updateById(ulong id, string name, string description);
}

interface TransactionCategoryRepository {
    Optional!TransactionCategory findById(ulong id);
    Optional!TransactionCategory findByName(string name);
    bool existsById(ulong id);
    bool existsByName(string name);
    TransactionCategory[] findAll();
    TransactionCategory[] findAllByParentId(Optional!ulong parentId);
    TransactionCategory insert(Optional!ulong parentId, string name, string description, string color);
    void deleteById(ulong id);
    TransactionCategory updateById(ulong id, string name, string description, string color);
}

interface TransactionTagRepository {
    string[] findAllByTransactionId(ulong transactionId);
    void updateTags(ulong transactionId, in string[] tags);
    string[] findAll();
}

interface TransactionRepository {
    Page!TransactionsListItem findAll(in PageRequest pr);
    Page!TransactionsListItem search(in PageRequest pr, in ServerHttpRequest request);
    Optional!TransactionDetail findById(ulong id);
    TransactionDetail insert(in AddTransactionPayload data);
    void linkAttachment(ulong transactionId, ulong attachmentId);
    TransactionDetail update(ulong transactionId, in AddTransactionPayload data);
    void deleteById(ulong id);
}
