Former correctional officer Rigoberto Sanchez took the stand in his murder trial Wednesday and testified the night he drove to his estranged wife's apartment his intention was only to fight his wife's lover, whom he'd long disliked and considered a "dirty cop" after working for years with him at a Tehachapi prison.

Sanchez said he confronted 33-year-old Edwin Lima outside the apartment in northeast Bakersfield. Lima called him earlier that evening, Sanchez said, and taunted him about having sex with his wife. Sanchez, Lima and Sanchez's wife all worked at California Correctional Institution in Tehachapi.

Instead of fighting, Lima went back inside the apartment.

Deciding to leave, Sanchez picked up a cinder block as he walked back to his car. He said he planned to throw it at Lima's truck.

But on the way he saw Lima look at him from a bedroom window, he said.

Sanchez said Lima told him, "Do you want to see a video of me (expletive) your daughter?"

Sanchez testified he threw the cinder block through the window. He said Lima then unholstered his handgun and began pointing it at him.

That's when, Sanchez testified, he raised his own gun and opened fire.

"I pulled my gun," he told the jury. "I began firing into his direction. I fired until my gun slide was stuck in the open position. I dropped the magazine. I reloaded."

He said his wife ran into another room, but when the door swung back she was pointing a gun at him. He then fired at but missed her.

Sanchez, 40, fled to Mexico following the May 28, 2017, shooting, and stayed with an uncle until he was tracked down weeks later.

He's charged with murder, attempted murder and other offenses and faces life in prison if convicted. The defense rested following Sanchez's roughly three-hour testimony, and on Thursday day the prosecution will call a rebuttal witness.

The defendant told the jury he feared for his life when Lima unholstered his gun. He said he fired in self-defense.

Prosecutor Gina Pearl, however, tore into that explanation. She has previously told the jury Sanchez was consumed by jealousy and shot at his wife and Lima in cold blood.

During cross-examination, Pearl told Sanchez he lied repeatedly following his arrest and never mentioned he fired in self-defense to Bakersfield police detectives during four hours of questioning.

In fact, she said, he told officers he was "going to be honest" more than 60 times during the interviews and instead did the opposite.

Sanchez told her he never lied. He said he withheld information.

Semantics also played a role in another exchange between Pearl and Sanchez when she questioned him about when he started dating other officers at work.

Sanchez said he didn't date anyone at work, he was just talking to a woman. Pearl asked him what's the difference.

"We're talking, are we dating?" Sanchez asked.

"No, we're not," Pearl said in a tone of apparent distaste.

Further questioning

There's a dispute between the defense and prosecution over how many times police interviewed Sanchez.

Pearl and Bakersfield police Detective Eric Littlefield, lead investigator in the case, said there were only two interviews. Sanchez and his attorney, Deputy Public Defender Paul Cadman, insist there were three, and that the third wasn't recorded.

In the third interview, Sanchez testified, he told Littlefield that he only owned two firearms, and other guns he had bought he sold to his brother. He said his brother couldn't buy certain guns so he bought them for him.

Sanchez testified Littlefield told him he did the same thing for family members even though it's a federal offense.

Pearl reacted in disbelief to that allegation.

"Seriously?" she said, her voice raised as she questioned Sanchez about this "secret" interview of which there's no evidence and in which, for some unknown reason, Littlefield would allegedly admit to a crime to a man charged with murder. Pearl said it never happened.

Sanchez maintained the interview took place and that's what Littlefield told him.

Asked how long he'd disliked Lima, Sanchez said his problems with the other officer began in 2012 when he learned of an incident where Lima and other officers were investigated for excessive use of force.

Sanchez said he believes Lima and others smuggled drugs, cellphones and other contraband into the prison, but admitted he has no evidence to support that allegation. He also admitted not having evidence to support his claim that Lima called him days before the shooting and threatened his brother, who is also a correctional officer who worked in Tehachapi.

In the months leading up to the shooting, Sanchez twice broke into his wife's apartment, once with the assistance of a homeless man whom he paid off with two cheeseburgers. Sanchez said the break-ins weren't motivated by jealousy; he was just trying to retrieve photos with sentimental value.

But Sanchez admitted he secretly obtained his wife's phone records in 2016 to see if she was seeing another man. He learned she was, and that the other man was Lima.

Pearl went over in detail Sanchez's actions leading up to the shooting in an effort to convince the jury he planned the killing.

Sanchez testified that before heading to his wife's apartment he packed bags with clothing and other belongings, dropped off a gun at his parents' house, took his stepdaughter's car to make it harder to find him and told his adult stepson not to stay at his mother's apartment that night.

In explaining his actions, Sanchez testified he packed the bags because he figured his career was over due to the burglaries. He planned to live in Mexico and start a new life. He said he took his stepdaughter's car because he knew police were looking for him in connection with the burglaries.

He testified he told his stepson to spend the night somewhere else because the stepson had been upset that day. And he said he dropped off one gun at his parents' home and kept the other for protection.

Pearl noted he kept his Glock handgun, which he said he didn't like as much as the Colt he left with his parents. She asked if it was just pure coincidence he kept the gun that could hold more bullets. Sanchez said he had magazines of various sizes for each gun.

The attorney also questioned why, if Sanchez just went to the apartment to fight, he walked to the front door holding the gun, gripping it so tightly it left an indentation in his hand that lasted for weeks.

Sanchez testified he carried the gun because he didn't want to get ambushed by Lima. He knew Lima also had a permit to carry a firearm while off-duty.

He said he didn't know whether he'd struck anyone after firing into the bedroom. It was later determined he fired a total of 21 rounds, 15 of which hit Lima.

Sanchez said he panicked and fled in his stepdaughter's car instead of waiting for police and explaining what happened. He testified it was one of many bad decisions he made that day.

Lima didn't deserve what happened, Sanchez said.

"I shouldn't have gone over there," he said. "I should have stayed away."