#include "G4HumanPhantomColour.h"
#include "G4HumanPhantomMaterial.h"
#include "G4VoxelLeftBreast.h"

#include "G4LogicalVolume.hh"
#include "G4Material.hh"
#include "G4PVPlacement.hh"
#include "G4PVReplica.hh"
#include "G4RotationMatrix.hh"
#include "G4SDManager.hh"
#include "G4SystemOfUnits.hh"
#include "G4ThreeVector.hh"
#include "G4Tubs.hh"
#include "G4VPhysicalVolume.hh"
#include "G4VisAttributes.hh"
#include "globals.hh"

G4VoxelLeftBreast::G4VoxelLeftBreast() {}

G4VoxelLeftBreast::~G4VoxelLeftBreast() {}

G4VPhysicalVolume* G4VoxelLeftBreast::Construct(const G4String& volumeName, G4VPhysicalVolume* mother,
                                                const G4String& colourName, G4bool wireFrame, G4bool)

{
    G4HumanPhantomMaterial* material = new G4HumanPhantomMaterial();
    G4Material* adipose = material->GetMaterial("adipose");
    G4Material* adipose_glandular = material->GetMaterial("adipose_glandular");
    delete material;

    G4double rmin = 0. * cm;
    G4double rmax = 6. * cm;
    G4double zz = 6. * cm;
    G4double startPhi = 0. * degree;
    G4double spanningPhi = 180. * degree;

    G4Tubs* breast = new G4Tubs("out_breast", rmin, rmax, zz / 2., startPhi, spanningPhi);

    G4LogicalVolume* breast_log = new G4LogicalVolume(breast, adipose, "logicalOut" + volumeName, 0, 0, 0);
    rmax = 5.5 * cm;
    zz = 5. * cm;
    G4Tubs* innerBreast = new G4Tubs("inner_breast", rmin, rmax, zz / 2., startPhi, spanningPhi);

    G4LogicalVolume* innerBreast_log =
        new G4LogicalVolume(innerBreast, adipose_glandular, "logical" + volumeName, 0, 0, 0);

    G4RotationMatrix* matrix = new G4RotationMatrix();
    // matrix -> rotateX(-90.* degree);
    // matrix -> rotateY(180.* degree);
    matrix->rotateZ(18. * degree);

    G4VPhysicalVolume* physBreast = new G4PVPlacement(matrix, G4ThreeVector(10. * cm, 8.7 * cm, 52. * cm),
                                                      "physicalVoxelLeftBreast", breast_log, mother, false, 0, true);

    G4VPhysicalVolume* physInnerBreast =
        new G4PVPlacement(0, G4ThreeVector(), "LeftBreast", innerBreast_log, physBreast, false, 0, true);

    G4HumanPhantomColour* colourPointer = new G4HumanPhantomColour();
    G4Colour colour = colourPointer->GetColour(colourName);
    delete colourPointer;

    G4VisAttributes* BreastVisAtt = new G4VisAttributes(colour);
    BreastVisAtt->SetForceSolid(wireFrame);
    breast_log->SetVisAttributes(BreastVisAtt);

    G4VisAttributes* innerBreastVisAtt = new G4VisAttributes(colour);
    innerBreastVisAtt->SetForceSolid(false);
    innerBreast_log->SetVisAttributes(innerBreastVisAtt);

    G4cout << "Voxel Left Breast created !!!!!! This model has to be refined" << G4endl;
    return physInnerBreast;
}
