import java.time.LocalDate;

// Satu baris jurnal stok: sekali dicatat, tidak pernah diubah (append-only).
public record MutasiStok(
        int id,
        String kodeBarang,
        JenisMutasi jenis,
        int jumlah,
        LocalDate tanggal,
        String petugas,
        String catatan) {

    public MutasiStok {
        if (id < 0) {
            throw new IllegalArgumentException("id mutasi tidak boleh negatif");
        }
        if (kodeBarang == null || kodeBarang.isBlank()) {
            throw new IllegalArgumentException("kode barang tidak boleh kosong");
        }
        if (jenis == null) {
            throw new IllegalArgumentException("jenis mutasi tidak boleh null");
        }
        if (jumlah <= 0) {
            throw new IllegalArgumentException("jumlah mutasi harus positif: " + jumlah);
        }
        if (tanggal == null) {
            throw new IllegalArgumentException("tanggal tidak boleh null");
        }
        if (petugas == null || petugas.isBlank()) {
            throw new IllegalArgumentException("petugas tidak boleh kosong");
        }
        if (catatan == null) {
            catatan = "";   // catatan opsional: null dirapikan menjadi string kosong
        }
    }

    @Override
    public String toString() {
        return "MutasiStok[id=" + id + ", kode=" + kodeBarang + ", " + jenis
                + " " + jumlah + ", tanggal=" + tanggal + ", petugas=" + petugas
                + ", catatan=" + catatan + "]";
    }
}
