package vato007:ingey;

interface types {
    resource csv-row {
        columns: func() -> list<string>;
        values: func() -> list<string>;
        entries: func() -> list<tuple<string, string>>;
        value: func(name: string) -> option<string>;
    }

    resource csv-reader {
        columns: func() -> list<string>;

        next: func() -> result<csv-row, string>;
        next-into-map: func() -> read-map;
        has-next: func() -> bool;

        // Get a row by values in one or more columns
        query: func(values: list<tuple<string, string>>) -> csv-row;

        read-into-string: func() -> string;
    }

    resource csv-readers {
        get-reader: func(name: string) -> option<csv-reader>;
    }

    resource csv-writer {
        write-row: func(row: list<tuple<string, string>>);
    }

    resource read-map {
        get: func(key: string) -> option<string>;
    }
}

// This will apply to csv files only for simplicity. A separate node should be created for arbitrary readers/writers
world dynamic {
    use types.{csv-readers, read-map, csv-writer};
    export evaluate: func(properties: read-map, readers: csv-readers, writer: csv-writer);
}