# user

username: admin
email: admin@micgo.pl
name: Główny Administrator
profile_pic: admin.webp
role: Właściciel
theme: dark
password_hash:
  scrypt:32768:8:1$iDYML3j0lSPP7k1C$31aa290256e2fe4cbc2ebdb580e492f4becd4279bcf07b017646c7437300d39c44e47d00250695070f945535a1ce79ece0726e73ca09b2376b9689beeba9e8af


username: michal.gonczerzewicz@micgo.pl
email: michalgon4@gmail.com
name: Michał Gonczerzewicz
profile_pic: admin.webp
role: UI/UX Designer
theme: dark
password_hash:
  scrypt:32768:8:1$uTs086kvs8SIo0rL$4180126e8f4201caf48c79a53c7cd723348b564e58496940d9f9d6f92f1480a94bab92f9e9cd50573e8671c5dabb8c430c59098c3944f5ca794cade0dbabe50f


# task

title: Analizator
status: W trakcie
created_at: 2026-05-23 10:43:01.414169
description:
  Branżowe Role IT: (CTO, Senior Developer, Frontend Developer, QA itp.).
  Edycja Zadań: Menedżer może edytować tytuł, opis, załączony kod i listę przypisanych osób.
  Środowisko Kodowania dla Pracownika: Pracownik ma osobny przycisk "Dodaj/Edytuj Kod Rozwiązania", który otwiera edytor stylizowany na VS Code (ciemne tło, monospace). Ten kod zapisuje się niezależnie od kodu załączonego w zadaniu i jest eksportowany do pliku Word.
  Profil Pracownika (Worker Details): Kliknięcie w pracownika w "Moja Firma" otwiera jego kartotekę z progresem zadań (Kanban style).

code_snippet:
  from flask_sqlalchemy import SQLAlchemy
  from flask_login import UserMixin
  from datetime import datetime

  db = SQLAlchemy()

  task_assignments = db.Table('task_assignments',
      db.Column('task_id', db.Integer, db.ForeignKey('task.id'), primary_key=True),
      db.Column('user_id', db.Integer, db.ForeignKey('user.id'), primary_key=True)
  )

employee_code_snippet:
  from flask_sqlalchemy import SQLAlchemy
  from flask_login import UserMixin
  from datetime import datetime

  db = SQLAlchemy()

  task_assignments = db.Table('task_assignments',
      db.Column('task_id', db.Integer, db.ForeignKey('task.id'), primary_key=True),
      db.Column('user_id', db.Integer, db.ForeignKey('user.id'), primary_key=True)
  )

  class Company(db.Model):
      id = db.Column(db.Integer, primary_key=True)
      name = db.Column(db.String(100), unique=True, nullable=False)
      domain = db.Column(db.String(100), nullable=False)
      users = db.relationship('User', backref='company', lazy=True, cascade="all, delete-orphan")

  class User(UserMixin, db.Model):
      id = db.Column(db.Integer, primary_key=True)
      username = db.Column(db.String(100), unique=True, nullable=False)
      email = db.Column(db.String(100), unique=True, nullable=False)
      password_hash = db.Column(db.String(200), nullable=False)
      name = db.Column(db.String(100))
      profile_pic = db.Column(db.String(200), default='admin.webp')

      company_id = db.Column(db.Integer, db.ForeignKey('company.id'), nullable=True)

      is_admin = db.Column(db.Boolean, default=False)
      is_company_admin = db.Column(db.Boolean, default=False)
      role = db.Column(db.String(50), default='Pracownik')

      needs_password_change = db.Column(db.Boolean, default=False)
      theme = db.Column(db.String(20), default='dark')

  class Message(db.Model):
      id = db.Column(db.Integer, primary_key=True)
      sender_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
      receiver_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
      body_encrypted = db.Column(db.LargeBinary, nullable=False) 
      timestamp = db.Column(db.DateTime, default=datetime.utcnow)
      is_read = db.Column(db.Boolean, default=False)

  class Ticket(db.Model):
      id = db.Column(db.Integer, primary_key=True)
      ticket_number = db.Column(db.String(20), unique=True, nullable=False)
      user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
      subject = db.Column(db.String(200), nullable=False)
      status = db.Column(db.String(50), default='Otwarty') 
      created_at = db.Column(db.DateTime, default=datetime.utcnow)
      
      user = db.relationship('User', backref='tickets')
      messages = db.relationship('TicketMessage', backref='ticket', cascade="all, delete-orphan")

  class TicketMessage(db.Model):
      id = db.Column(db.Integer, primary_key=True)
      ticket_id = db.Column(db.Integer, db.ForeignKey('ticket.id'), nullable=False)
      sender_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
      body = db.Column(db.Text, nullable=False)
      timestamp = db.Column(db.DateTime, default=datetime.utcnow)
      is_admin_reply = db.Column(db.Boolean, default=False)
      sender = db.relationship('User')

  # ==========================
  # SYSTEM ZADAŃ (TASK MANAGER)
  # ==========================
  class Task(db.Model):
      id = db.Column(db.Integer, primary_key=True)
      company_id = db.Column(db.Integer, db.ForeignKey('company.id'), nullable=False)
      creator_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
      
      title = db.Column(db.String(200), nullable=False)
      description = db.Column(db.Text, nullable=True)
      code_snippet = db.Column(db.Text, nullable=True) # Kod wstawiony przez managera
      employee_code_snippet = db.Column(db.Text, nullable=True) # Kod napisany przez pracownika
      
      status = db.Column(db.String(50), default='W trakcie') 
      created_at = db.Column(db.DateTime, default=datetime.utcnow)

      creator = db.relationship('User', foreign_keys=[creator_id])
      assignees = db.relationship('User', secondary=task_assignments, backref='tasks')
      comments = db.relationship('TaskComment', backref='task', cascade="all, delete-orphan")

  class TaskComment(db.Model):
      id = db.Column(db.Integer, primary_key=True)
      task_id = db.Column(db.Integer, db.ForeignKey('task.id'), nullable=False)
      user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
      body = db.Column(db.Text, nullable=False)
      timestamp = db.Column(db.DateTime, default=datetime.utcnow)
      
      user = db.relationship('User')


