CREATE TABLE users (
    id            INT IDENTITY PRIMARY KEY,
    username      NVARCHAR(100) NOT NULL UNIQUE,
    email         NVARCHAR(200) NOT NULL UNIQUE,
    display_name  NVARCHAR(200),
    password_hash NVARCHAR(200) NOT NULL,
    role          NVARCHAR(30)  NOT NULL DEFAULT 'viewer',
    avatar_url    NVARCHAR(500),
    active        BIT           NOT NULL DEFAULT 1,
    last_login    DATETIME2,
    created_at    DATETIME2     NOT NULL DEFAULT GETUTCDATE(),
    CONSTRAINT chk_user_role CHECK (role IN ('admin','dispatcher','field_tech','viewer'))
);

CREATE INDEX ix_users_username ON users (username);
CREATE INDEX ix_users_email    ON users (email);
