import os
from reportlab.lib.pagesizes import A4
from reportlab.lib import colors
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer, Table, TableStyle, HRFlowable
from reportlab.lib.units import cm

pdf_path = "/home/magdalena/eee/alunos/rafael-rosa-batista/Caso_de_Uso_Barco_Passeio_5m.pdf"

doc = SimpleDocTemplate(
    pdf_path,
    pagesize=A4,
    leftMargin=2*cm,
    rightMargin=2*cm,
    topMargin=2*cm,
    bottomMargin=2*cm
)

styles = getSampleStyleSheet()

primary_color = colors.HexColor("#1A365D")
secondary_color = colors.HexColor("#2B6CB0")
dark_neutral = colors.HexColor("#2D3748")
table_header_bg = colors.HexColor("#EBF8FF")

title_style = ParagraphStyle(
    'DocTitle',
    parent=styles['Normal'],
    fontName='Helvetica-Bold',
    fontSize=18,
    leading=22,
    textColor=primary_color,
    spaceAfter=4
)

subtitle_style = ParagraphStyle(
    'DocSubTitle',
    parent=styles['Normal'],
    fontName='Helvetica',
    fontSize=10.5,
    leading=14,
    textColor=secondary_color,
    spaceAfter=12
)

h1_style = ParagraphStyle(
    'Heading1_Custom',
    parent=styles['Normal'],
    fontName='Helvetica-Bold',
    fontSize=12,
    leading=16,
    textColor=primary_color,
    spaceBefore=10,
    spaceAfter=5
)

body_style = ParagraphStyle(
    'Body_Custom',
    parent=styles['Normal'],
    fontName='Helvetica',
    fontSize=9,
    leading=13,
    textColor=dark_neutral,
    spaceAfter=4
)

bullet_style = ParagraphStyle(
    'Bullet_Custom',
    parent=styles['Normal'],
    fontName='Helvetica',
    fontSize=9,
    leading=13,
    textColor=dark_neutral,
    leftIndent=12,
    spaceAfter=3
)

story = []

# Header
story.append(Paragraph("CASO DE USO E DECLARAÇÃO DE REQUISITOS", title_style))
story.append(Paragraph("<b>Projeto:</b> Barco de Passeio Fluvial 5,0 m (16,4 pés)<br/><b>Projetista / Aluno:</b> Rafael Rosa Batista | <b>Instituição:</b> Brana / Estaleiro Escola Embrião (EEE)", subtitle_style))
story.append(HRFlowable(width="100%", thickness=1.5, color=secondary_color, spaceBefore=0, spaceAfter=10))

# 1. Missão
story.append(Paragraph("1. Missão Principal e Perfil de Utilização", h1_style))
story.append(Paragraph("Embarcação cabinada aberta destinada ao lazer diurno, passeios familiares e pequenas pescarias esportivas em ambiente fluvial.", body_style))
story.append(Paragraph("• <b>Atividades:</b> Passeio recreativo, banho de rio, circulação confortável e contemplação.", bullet_style))
story.append(Paragraph("• <b>Regime de Operação:</b> Diurno, saídas de curta e média duração (3 a 6 horas).", bullet_style))

# 2. Área de Operação
story.append(Paragraph("2. Área e Condições Ambientais de Operação", h1_style))
story.append(Paragraph("• <b>Região:</b> Rios, lagoas e águas interiores abrigadas (Área 1 - Interior / NORMAM-02/DPC).", bullet_style))
story.append(Paragraph("• <b>Restrições Físicas:</b> Presença de baixios e bancos de areia móveis exigindo calado reduzido (< 0,30 m).", bullet_style))
story.append(Paragraph("• <b>Correntes Fluviais:</b> Necessidade de leme ágil e resposta de aceleração para controle em correntezas.", bullet_style))

# 3. Lotação e Capacidades
story.append(Paragraph("3. Lotação, Pesos e Capacidades de Carga", h1_style))
data_cap = [
    [Paragraph("<b>Item</b>", body_style), Paragraph("<b>Especificação de Projeto</b>", body_style), Paragraph("<b>Impacto no Projeto</b>", body_style)],
    [Paragraph("Lotação Nominal", body_style), Paragraph("4 pessoas (300 kg)", body_style), Paragraph("2 no banco dianteiro + 2 no banco traseiro", body_style)],
    [Paragraph("Bagagem / Provisões", body_style), Paragraph("40 kg a 50 kg (cooler, tralha)", body_style), Paragraph("Espaço livre no piso central", body_style)],
    [Paragraph("Combustível", body_style), Paragraph("Tanque portátil de 25 L a 40 L", body_style), Paragraph("Alojado em caixa estanque na popa", body_style)],
    [Paragraph("Deslocamento Máximo", body_style), Paragraph("~750 kg a 800 kg (Carregado)", body_style), Paragraph("Base de cálculo para hidrostática e flutuação", body_style)]
]
t_cap = Table(data_cap, colWidths=[4.2*cm, 5.0*cm, 7.8*cm])
t_cap.setStyle(TableStyle([
    ('BACKGROUND', (0, 0), (-1, 0), table_header_bg),
    ('GRID', (0, 0), (-1, -1), 0.5, colors.HexColor("#CBD5E0")),
    ('VALIGN', (0, 0), (-1, -1), 'MIDDLE'),
    ('TOPPADDING', (0, 0), (-1, -1), 3),
    ('BOTTOMPADDING', (0, 0), (-1, -1), 3),
]))
story.append(t_cap)

# 4. Geometria Principal
story.append(Paragraph("4. Dimensões Principais e Forma do Casco", h1_style))
data_geom = [
    [Paragraph("<b>Dimensão / Parâmetro</b>", body_style), Paragraph("<b>Valor Alvo</b>", body_style), Paragraph("<b>Justificativa Técnica</b>", body_style)],
    [Paragraph("Comprimento Total (LOA)", body_style), Paragraph("5,00 m (16,4 pés)", body_style), Paragraph("Facilidade de manobra, reboque e guarda", body_style)],
    [Paragraph("Boca Máxima (B)", body_style), Paragraph("1,95 m", body_style), Paragraph("Garante alta estabilidade transversal inicial (GM)", body_style)],
    [Paragraph("Pontal Moldado (D)", body_style), Paragraph("0,85 m", body_style), Paragraph("Borda livre confortável (> 0,55 m carregado)", body_style)],
    [Paragraph("Calado Máximo (T)", body_style), Paragraph("0,25 m a 0,28 m", body_style), Paragraph("Permite encalhar e passar em praias fluviais", body_style)],
    [Paragraph("Geometria de Fundo", body_style), Paragraph("Quina Viva (Hard Chine) em V", body_style), Paragraph("V progressivo (28° proa -> 13° popa)", body_style)],
]
t_geom = Table(data_geom, colWidths=[4.5*cm, 4.2*cm, 8.3*cm])
t_geom.setStyle(TableStyle([
    ('BACKGROUND', (0, 0), (-1, 0), table_header_bg),
    ('GRID', (0, 0), (-1, -1), 0.5, colors.HexColor("#CBD5E0")),
    ('VALIGN', (0, 0), (-1, -1), 'MIDDLE'),
    ('TOPPADDING', (0, 0), (-1, -1), 3),
    ('BOTTOMPADDING', (0, 0), (-1, -1), 3),
]))
story.append(t_geom)

# 5. Desempenho e Propulsão
story.append(Paragraph("5. Requisitos de Propulsão e Desempenho", h1_style))
story.append(Paragraph("• <b>Tipo de Motor:</b> Motor de Popa de 30 HP a 40 HP (Gasolina, 2T ou 4T).", bullet_style))
story.append(Paragraph("• <b>Velocidade de Cruzeiro:</b> 18 a 22 nós (~33 a 40 km/h) com excelente rendimento de combustível.", bullet_style))
story.append(Paragraph("• <b>Velocidade Máxima:</b> 26 a 30 nós (~48 a 55 km/h).", bullet_style))
story.append(Paragraph("• <b>Autonomia Desejada:</b> 50 a 60 milhas náuticas com margem de segurança de 20%.", bullet_style))

# 6. Método Construtivo e Materiais
story.append(Paragraph("6. Método Construtivo e Materiais Selecionados", h1_style))
story.append(Paragraph("• <b>Processo:</b> Madeira e resina epóxi (<i>Stitch-and-Glue</i> com compensado naval).", bullet_style))
story.append(Paragraph("• <b>Chapas:</b> Compensado naval de 10 mm (fundo/popa) e 6-8 mm (costados/bancos).", bullet_style))
story.append(Paragraph("• <b>Madeira Maciça Nobre:</b> Jaqueira para roda de proa, verdugos externos e quilha de proteção.", bullet_style))
story.append(Paragraph("• <b>Laminação e Proteção:</b> Tecido de fibra de vidro 300 g/m² resinado com epóxi externo.", bullet_style))

# 7. Segurança
story.append(Paragraph("7. Requisitos de Segurança e Normas Aplicáveis", h1_style))
story.append(Paragraph("• Câmaras de flutuação positiva estanques na proa (paiol) e nos cantos de popa (barco insubmergível).", bullet_style))
story.append(Paragraph("• Atendimento integral às diretrizes da <b>NORMAM-02/DPC</b> para esporte e recreio em navegação interior.", bullet_style))

doc.build(story)
print("Caso de Uso PDF created.")
