/*
machine-(n)---(1)-crawler
machine-(n)---(1)-state
machine-(n)---(1)-transistion
state-(n)-----(2)-transistion
machine-<>--------payload
crawler-<>--------payload
crawler---------->machine
*/
DROP TABLE IF EXISTS fsm_payload;
DROP TABLE IF EXISTS fsm_crawler;
DROP TABLE IF EXISTS fsm_transition;
DROP TABLE IF EXISTS fsm_state;
DROP TABLE IF EXISTS fsm_machine;

CREATE TABLE fsm_machine (
    id INTEGER PRIMARY KEY ASC
);

CREATE TABLE fsm_state (
    id INTEGER PRIMARY KEY ASC,
    machine_id INTEGER NOT NULL,
    FOREIGN KEY(machine_id) REFERENCES fsm_machine(id)
);

CREATE TABLE fsm_transition (
    id INTEGER PRIMARY KEY ASC,
    from_state_id INTEGER NOT NULL,
    to_state_id INTEGER NOT NULL,
    FOREIGN KEY(from_state_id) REFERENCES fsm_state(id),
    FOREIGN KEY(to_state_id) REFERENCES fsm_state(id)
);
-- fsm_transition_predicate
-- from payload
-- value vs value
-- value vs const
-- == != < > <= >= 


CREATE TABLE fsm_crawler (
    id INTEGER PRIMARY KEY ASC,
    state_id INTEGER NOT NULL,
    FOREIGN KEY(state_id) REFERENCES fsm_state(id)
);

CREATE TABLE fsm_payload (
    id INTEGER PRIMARY KEY ASC,
    machine_id INTEGER NOT NULL,
    FOREIGN KEY(machine_id) REFERENCES fsm_machine(id)
);
-- fsm_payload_key for performance
-- view that yield crawler payload with state machine payload
-- some element can be dynamicly calculated and will be included in the view

-- predicate
-- value == value
-- transform
-- value -> const

